This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector <pair <int, int>> updates(n);
for (int i = 0; i < n; i++) {
cin >> updates[i].first >> updates[i].second;
}
sort(updates.begin(), updates.end());
ll ans = 0;
priority_queue <ll> pq;
for (int i = 0; i < n; i++) {
if (i == 0) {
for (int j = 1; j <= updates[i].first; j++)
pq.push(0);
} else {
for (int j = updates[i-1].first+1; j <= updates[i].first; j++)
pq.push(0);
}
vector <ll> to_add(updates[i].second);
for (int j = 0; j < updates[i].second; j++) {
ll x = pq.top();
pq.pop();
ans += (-x);
to_add[j] = x - 1;
}
for (auto i : to_add)
pq.push(i);
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |