# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
285140 | Pyqe | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 228 ms | 15336 KiB |
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;
long long n,ps[500069];
priority_queue<long long> pq;
int main()
{
long long i,ii,k,l,z=0;
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
scanf("%lld%lld",&k,&l);
ps[i]=ps[i-1]+k-l;
}
for(i=1;i<n;i++)
{
k=min(max(ps[i],0ll),ps[n]);
z+=abs(k-ps[i]);
ps[i]=k;
if(i-1)
{
z+=max(pq.top()-ps[i],0ll);
}
for(ii=0;ii<2;ii++)
{
pq.push(ps[i]);
}
pq.pop();
}
printf("%lld\n",z);
}
Compilation message (stderr)
# | 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... |