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 <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int N;
cin >> N;
vector<pair<int, int>> masts;
priority_queue<int, vector<int>, greater<int>> pq;
FR(i, N) {
int h, k;
cin >> h >> k;
masts.push_back({h, k});
}
sort(all(masts));
// int costs[100000];
int last = 0;
ll ans = 0;
vector<int> remd;
FR(i, N) {
remd.clear();
while (last<masts[i].first) {
pq.push(0);
last++;
}
while (masts[i].second-->0) {
int next = pq.top();
pq.pop();
ans += next;
next++;
remd.push_back(next);
}
for (auto& a : remd) {
pq.push(a);
}
}
cout << ans << '\n';
return 0;
}
# | 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... |