// PA2024 runda 1B - https://sio2.mimuw.edu.pl/c/pa-2024-1/p/lid/ //-std=c++20 #include<iostream> #include <cstddef> #include<list> #include <algorithm> using I = u_int64_t; //12:40 - 13:05, 10 min int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); I n; std::cin >> n; I series[n]; for (int i = 0; i < n; ++i) { std::cin >> series[i]; } std::sort(series, series + n); std::list<I> counts; I c = 1; for (I i = 1; i < n; i++) { if (series[i] != series[i - 1]) { counts.push_back(c); c = 1; } else { c++; } } counts.push_back(c); counts.sort(); //asc I result = 0; auto i = counts.begin(); auto j = counts.end(); while (j != i) { I sum = 0; result++; j--; while (sum + (*i) < (*j) && i != j) { sum += *i; i++; } if (i != j) { I allowed = (*j) - sum - 1; (*i) -= allowed; } } std::cout << result; }
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 | // PA2024 runda 1B - https://sio2.mimuw.edu.pl/c/pa-2024-1/p/lid/ //-std=c++20 #include<iostream> #include <cstddef> #include<list> #include <algorithm> using I = u_int64_t; //12:40 - 13:05, 10 min int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); I n; std::cin >> n; I series[n]; for (int i = 0; i < n; ++i) { std::cin >> series[i]; } std::sort(series, series + n); std::list<I> counts; I c = 1; for (I i = 1; i < n; i++) { if (series[i] != series[i - 1]) { counts.push_back(c); c = 1; } else { c++; } } counts.push_back(c); counts.sort(); //asc I result = 0; auto i = counts.begin(); auto j = counts.end(); while (j != i) { I sum = 0; result++; j--; while (sum + (*i) < (*j) && i != j) { sum += *i; i++; } if (i != j) { I allowed = (*j) - sum - 1; (*i) -= allowed; } } std::cout << result; } |