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;
int main()
{
int n;
cin>>n;
vector<long long>odp1(n);
priority_queue<long long,vector<long long>,greater<long long>>odp2;
for(auto &x : odp1)
{
int a,b;
cin>>a>>b;
x=(a-b);
odp2.push(0);
}
partial_sum(odp1.begin(),odp1.end(),odp1.begin());
odp2.push(0);
odp2.push(0);
int punkty=0;
for(auto x : odp1 )
{
odp2.pop();
punkty+=max(-x-odp2.top(),0LL);
odp2.push(-x);
odp2.push(-x);
}
long long wi=0;
while(odp2.top()!=-odp1.back())
{
auto m=odp2.top();
odp2.pop();
punkty+=wi*(odp2.top()-m);
wi++;
}
cout<<punkty;
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... |