#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define P(a,n) for(int j=a;j<n;j++)
#define P3(a,n,z) for(int z=a;z<n;z++)
#define PD(pocz,kon,z) for(int z=pocz;z>=kon;z--)
#define W while
#define PB push_back
#define F first
#define S second
#define ll long long
#define O cout<<
#define I cin>>
#define endl '\n'
#define E '\n'
using namespace std;
/** Do najwiekszej grupy bedziemy w tym programie po kolei przydzielac elementy ktorych ilosciowo jest najmniej
***Dowod dzialania?? Proof of work./ **/
constexpr int MN=500'004;
int il[MN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL);
int n,a;
I n;
P(0,n)
{ I a; il[a]++;}
sort(il,il+n);
int dx=0,gx=n-1;
W(dx<gx)
{
W(il[gx]>1 && dx<gx)
{
if(il[dx]>0)
{ il[dx]--;il[gx]--;}
else
dx++;
}
gx--;
}
a=0;
P(0,n)
if(il[j]>0)a++;
O a;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <iostream> #include <algorithm> #include <vector> #include <map> #define P(a,n) for(int j=a;j<n;j++) #define P3(a,n,z) for(int z=a;z<n;z++) #define PD(pocz,kon,z) for(int z=pocz;z>=kon;z--) #define W while #define PB push_back #define F first #define S second #define ll long long #define O cout<< #define I cin>> #define endl '\n' #define E '\n' using namespace std; /** Do najwiekszej grupy bedziemy w tym programie po kolei przydzielac elementy ktorych ilosciowo jest najmniej ***Dowod dzialania?? Proof of work./ **/ constexpr int MN=500'004; int il[MN]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n,a; I n; P(0,n) { I a; il[a]++;} sort(il,il+n); int dx=0,gx=n-1; W(dx<gx) { W(il[gx]>1 && dx<gx) { if(il[dx]>0) { il[dx]--;il[gx]--;} else dx++; } gx--; } a=0; P(0,n) if(il[j]>0)a++; O a; return 0; } |
English