#include<cstdio> #include<algorithm> #define S 500007 using namespace std; int T[S]; int main(void){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++){ int x; scanf("%d", &x); T[x]++; } sort(T+1, T+n+1); int ans = 0; int l = 1; for(int i = n; i >= 1; i--){ if(T[i] == 0) break; int p = T[i] - 1; while(l < i && p > 0){ int c = min(p, T[l]); T[l] -= c; p -= c; if(T[l] == 0) l++; } ans++; } printf("%d\n",ans); 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 | #include<cstdio> #include<algorithm> #define S 500007 using namespace std; int T[S]; int main(void){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++){ int x; scanf("%d", &x); T[x]++; } sort(T+1, T+n+1); int ans = 0; int l = 1; for(int i = n; i >= 1; i--){ if(T[i] == 0) break; int p = T[i] - 1; while(l < i && p > 0){ int c = min(p, T[l]); T[l] -= c; p -= c; if(T[l] == 0) l++; } ans++; } printf("%d\n",ans); return 0; } |