Submission #918015

#TimeUsernameProblemLanguageResultExecution timeMemory
918015abczzSails (IOI07_sails)C++14
55 / 100
56 ms2804 KiB
#include <iostream> #include <vector> #include <array> #define ll long long using namespace std; bool ok; vector <ll> V; ll n, a, b, k, l, r, z, mid, s, t, f, ps[100001], dlt[100001], cnt[100001]; int main() { cin >> n; for (int i=0; i<n; ++i) { cin >> a >> b; --a; ps[a] += b; t += b; ++cnt[a+1]; } for (int i=1; i<100000; ++i) { ps[i] += ps[i-1]; cnt[i] += cnt[i-1]; } l = 0, r = n; while (l < r) { mid = (l+r)/2; s = 0; ok = 1; for (int i=0; i<100000; ++i) { s += min(n-cnt[i], mid); if (s < ps[i]) { ok = 0; break; } } if (ok) r = mid; else l = mid+1; } for (int i=0; i<100000; ++i) { s = min(n-cnt[i], l); z += s; dlt[i] = z-ps[i]; f += s * (s-1) / 2; } for (int i=99998; i>=0; --i) { dlt[i] = min(dlt[i], dlt[i+1]); } k = 0; for (int i=0; i<100000; ++i) { if (dlt[i] > k) { ++k; f -= min(n-cnt[i], l)-1; } } cout << f << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...