Submission #918018

#TimeUsernameProblemLanguageResultExecution timeMemory
918018abczzSails (IOI07_sails)C++14
55 / 100
63 ms5828 KiB
#include <iostream> #include <vector> #include <array> #include <queue> #define ll long long using namespace std; bool ok; vector <ll> V; priority_queue<array<ll, 2>> pq; 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]); } for (int i=0; i<100000; ++i) { pq.push({min(n-cnt[i], l), dlt[i]}); } k = 0; while (!pq.empty()) { auto [w, u] = pq.top(); pq.pop(); if (u > k) { f -= w-1; ++k; pq.push({w-1, u}); } } cout << f << '\n'; }

Compilation message (stderr)

sails.cpp: In function 'int main()':
sails.cpp:56:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |     auto [w, u] = pq.top();
      |          ^
#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...