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;
priority_queue <pair <ll, int>> pq;
vector <pair <int, int>> updates(n);
int maxh = 0;
for (int i = 0; i < n; i++) {
cin >> updates[i].first >> updates[i].second;
maxh = max(maxh, updates[i].first);
}
for (int i = 1; i <= maxh; i++)
pq.push({0, i});
sort(updates.begin(), updates.end());
ll ans = 0;
for (int i = 0; i < n; i++) {
priority_queue <pair <ll, int>> tp;
int done = 0;
while (done < updates[i].second) {
pair <ll, int> x = pq.top();
pq.pop();
if (x.second <= updates[i].first) {
ans += (-x.first);
tp.push({x.first-1, x.second});
done++;
} else {
tp.push(x);
}
}
while (!tp.empty()) {
pq.push(tp.top());
tp.pop();
}
}
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... |