1195A - Drinks Choosing - CodeForces Solution


greedy math *1000

Please click on ads to support us..

Python Code:

n=int(input().split()[0])
c=[0]*1001
for _ in[0]*n:c[int(input())]+=1
print(n-sum(x%2for x in c)//2)

C++ Code:

// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t, k;
    cin >> t >> k;
     vector<int> arr(t);
     for(auto &it:arr) {cin >> it;}
     vector<int> f(k+1, 0);
for(auto it:arr) {
    f[it]++;
}
int count = 0, rem=0;
for(int i = 1; i<=k; ++i){
    count += (f[i]/2);
    rem += (f[i]%2);
}
cout << (count*2) +((t+1)/2)-count;
    return 0;
}


Comments

Submit
0 Comments
More Questions

1388A - Captain Flint and Crew Recruitment
592B - The Monster and the Squirrel
1081A - Definite Game
721C - Journey
1400A - String Similarity
1734E - Rectangular Congruence
1312D - Count the Arrays
424C - Magic Formulas
1730C - Minimum Notation
1730B - Meeting on the Line
1730A - Planets
302B - Eugeny and Play List
1730D - Prefixes and Suffixes
1515C - Phoenix and Towers
998A - Balloons
1734F - Zeros and Ones
1144B - Parity Alternated Deletions
92B - Binary Number
1144C - Two Shuffled Sequences
1154B - Make Them Equal
1272B - Snow Walking Robot
522B - Photo to Remember
608B - Hamming Distance Sum
1408F - Two Different
274B - Zero Tree
1726H - Mainak and the Bleeding Polygon
722A - Broken Clock
129B - Students and Shoelaces
697B - Barnicle
903D - Almost Difference