#include <cstdio> int p[500000], q[500000]; int main() { int n, a, r=0, s=0; scanf("%i", &n); for (int i = 0; i<n; i++) { scanf("%i", &a); p[a-1]++; } for (int i = 0; i<n; i++) if (p[i]>0) q[p[i]-1]++; for (int i = n-1; i>=0; i--) for (int j = 1; j<=q[i]; j++) { r++; s+=i+1; if (s-r>=n-s) { printf("%i\n", r); return 0; } } 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 | #include <cstdio> int p[500000], q[500000]; int main() { int n, a, r=0, s=0; scanf("%i", &n); for (int i = 0; i<n; i++) { scanf("%i", &a); p[a-1]++; } for (int i = 0; i<n; i++) if (p[i]>0) q[p[i]-1]++; for (int i = n-1; i>=0; i--) for (int j = 1; j<=q[i]; j++) { r++; s+=i+1; if (s-r>=n-s) { printf("%i\n", r); return 0; } } return 0; } |