# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471561 | CaroLinda | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 1 ms | 204 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>
#define debug
#define ll long long
const int MAXN = 5e5+10 ;
using namespace std ;
int N ;
ll C[MAXN] , x , y ;
ll ans , p ;
priority_queue< ll > q ;
int main()
{
scanf("%d", &N ) ;
for(int i = 0 ; i < N ; i++ )
{
scanf("%lld %lld", &x, &y ) ;
C[i] = x-y ;
C[i] += C[i-1] ;
}
for(int i = 0 ; i < N ; i++ )
{
if(C[i] < 0 ) ans -= C[i] , C[i] = 0 ;
if(C[i] > C[N-1] ) ans += C[i]-C[N-1] , C[i] = C[N-1] ;
q.push(C[i]) ;
q.push(C[i]) ;
ans += abs(q.top()-C[i]) ;
q.pop() ;
}
printf("%lld\n" , ans ) ;
}
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... |