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 pii pair<int,int>
using namespace std;
typedef long long ll;
struct ura {
int h, k;
};
int n;
int max_alt;
ura masts[100005];
int alturas[100005];
ll resp;
priority_queue<int> q;
bool cmp(ura &a, ura &b) {
return a.h < b.h;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=0; i<n; i++) {
cin >> masts[i].h >> masts[i].k;
}
sort(masts, masts+n, cmp);
vector<int> add;
int a;
for(int i=0; i<n; i++) {
while (!add.empty()) {
q.push(add.back());
add.pop_back();
}
while (max_alt < masts[i].h) {
q.push(0);
max_alt++;
}
while (masts[i].k--) {
a = q.top();
q.pop();
add.push_back(a-1);
resp += a * -1;
}
}
cout << resp;
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... |