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>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nums; cin >> nums;
priority_queue<ll> pq;
vector<ll> pref(nums + 1);
pref[0] = 0;
for (int i = 1; i <= nums; i++){
ll s, d; cin >> s >> d;
pref[i] = pref[i - 1] + s - d;
}
ll ans = 0;
for (int i = 1; i <= nums; i++){
if (pref[i] < 0) {
ans -= pref[i];
pref[i] = 0;
}
else if (pref[i] > pref[nums]){
ans += pref[i] - pref[nums];
pref[i] = pref[nums];
}
pq.push(pref[i]);
pq.push(pref[i]);
ans += pq.top() - pref[i];
pq.pop();
}
cout << ans;
}
# | 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... |