Submission #392887

#TimeUsernameProblemLanguageResultExecution timeMemory
392887Aldas25Sails (IOI07_sails)C++14
40 / 100
1092 ms6964 KiB
#include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define f first #define s second #define pb push_back typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef long long ll; const int MAXN = 100100; int n; vii seq; ll cnt[MAXN]; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q; vector<pair<ll, int>> rem; int main() { FAST_IO; cin >> n; REP(n) { int h, k; cin >> h >> k; seq.pb({h, k}); } sort(seq.begin(), seq.end()); ll ans = 0; FOR(i, 0, n-1) { int lst = i==0 ? 0 : seq[i-1].f; int h = seq[i].f; int k = seq[i].s; FOR(j, lst+1, h) { q.push({0, j}); } rem.clear(); REP(k) { auto pp = q.top(); q.pop(); int j = pp.s; cnt[j]++; rem.pb({cnt[j], j}); } for (auto pp : rem) q.push(pp); lst = h; } FOR(i, 0, MAXN-1) { if (cnt[i] == 0) continue; ans += (cnt[i] * (cnt[i]-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...