#include "bits/stdc++.h" using namespace std; const double ice_per_year = 252e9; const double secs_in_year = 365.0 * 24.0 * 60.0 * 60.0; const double ice_per_sec = ice_per_year / secs_in_year; mt19937_64 rng(42); int main() { int n = 1e5; long long k = 1e12; vector<double> a(n); for (int i = 0; i < n; ++i) { a[i] = rng() % ((long long)1e12) + 1; } vector<double> c(n, 1); priority_queue<pair<double, int>> pq; for (int i = 0; i < n; ++i) { pq.emplace(a[i] / c[i] / (c[i] + 1), i); } cerr << "ice melts per sec in antarctica: " << ice_per_sec << endl; auto start_time = clock(); for (long long i = 0; i < k - n; ++i) { int ind = pq.top().second; pq.pop(); c[ind] += 1; pq.emplace(a[ind] / c[ind] / (c[ind] + 1), ind); if (i % ((int)1e7) == 0) { double spent_time = (double)(clock() - start_time) / CLOCKS_PER_SEC; double estimated_runtime = spent_time / (i + 1) * (k - n); cerr << i << ", spent time: " << spent_time << "s, estimated runtime: " << estimated_runtime << "s"; cerr << ", estimated ice melts: " << ice_per_sec * estimated_runtime; cerr << endl; } } double ans = 0; for (int i = 0; i < n; ++i) { ans += a[i] / c[i]; } cout << (long long)(ans + 0.5) << '\n'; return 0; }
Standard input is empty
Standard output is empty
ice melts per sec in antarctica: 7990.87 0, spent time: 1e-06s, estimated runtime: 1e+06s, estimated ice melts: 7.99087e+09 10000000, spent time: 1.43957s, estimated runtime: 143957s, estimated ice melts: 1.15034e+09 20000000, spent time: 2.87003s, estimated runtime: 143501s, estimated ice melts: 1.1467e+09 30000000, spent time: 4.29899s, estimated runtime: 143300s, estimated ice melts: 1.14509e+09 40000000, spent time: 5.7271s, estimated runtime: 143178s, estimated ice melts: 1.14411e+09 50000000, spent time: 7.17569s, estimated runtime: 143514s, estimated ice melts: 1.1468e+09 60000000, spent time: 8.60978s, estimated runtime: 143496s, estimated ice melts: 1.14666e+09 70000000, spent time: 10.0289s, estimated runtime: 143270s, estimated ice melts: 1.14485e+09 80000000, spent time: 11.4056s, estimated runtime: 142570s, estimated ice melts: 1.13926e+09 90000000, spent time: 12.8349s, estimated runtime: 142610s, estimated ice melts: 1.13957e+09 100000000, spent time: 14.2414s, estimated runtime: 142413s, estimated ice melts: 1.13801e+09