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 n;
ll f = 0;
priority_queue<ll> Q; //punkty przegiecia DP
int main() {
cin >> n;
vector<ll> pref(n+1);
for (int i=1; i<=n; i++) {
int a, b;
cin >> a >> b;
pref[i] = a - b + pref[i - 1];
}
for (int i=1; i<n; i++){
if(pref[i] < 0){
f -= pref[i];
pref[i] = 0;
}
f += pref[i];
Q.push(pref[i]);
Q.push(pref[i]);
Q.pop();
}
while (Q.size()) {
ll tmp = Q.top();
Q.pop();
f -= min(tmp, pref[n]);
}
cout << f << "\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... |