Submission #502868

#TimeUsernameProblemLanguageResultExecution timeMemory
502868tabrSails (IOI07_sails)C++17
50 / 100
1092 ms2356 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; const int m = (int) 1e5 + 10; vector<int> a(m); for (int i = 0; i < n; i++) { int h, k; cin >> h >> k; a[h]--; a[h - k]++; } for (int i = 0; i < m - 1; i++) { a[i + 1] += a[i]; } priority_queue<int> pq; pq.emplace(0); for (int i = m - 1; i >= 0; i--) { while (pq.top() - 1 >= a[i] + 1) { int b = pq.top(); a[i]++; b--; pq.pop(); pq.emplace(b); } pq.emplace(a[i]); } long long ans = 0; while (!pq.empty()) { int b = pq.top(); pq.pop(); ans += 1LL * b * (b - 1) / 2; } cout << ans << '\n'; return 0; }
#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...