Submission #151891

# Submission time Handle Problem Language Result Execution time Memory
151891 2019-09-05T10:07:54 Z Bodo171 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
200 ms 8684 KB
#include <iostream>
#include <queue>
using namespace std;

const int nmax=500005;
priority_queue<long long> pq;
long long c[nmax];
long long ans;
int n,i,j,a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a>>b;
        long long dif=a-b;
        c[i]=(c[i-1]+dif);
    }
    for(i=1;i<=n;i++)
    {
        if(c[i]<0) ans-=c[i],c[i]=0;
        if(c[i]>c[n]) ans+=(c[i]-c[n]),c[i]=c[n];
    }
    for(i=1;i<=n;i++)
    {
        pq.push(c[i]);
        if(pq.top()>c[i])
        {
            pq.push(c[i]);
            ans+=1LL*pq.top()-c[i];
            pq.pop();
        }
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 12 ms 1404 KB Output is correct
5 Correct 22 ms 2292 KB Output is correct
6 Correct 66 ms 4436 KB Output is correct
7 Correct 130 ms 8552 KB Output is correct
8 Correct 112 ms 8644 KB Output is correct
9 Correct 108 ms 8524 KB Output is correct
10 Correct 83 ms 8420 KB Output is correct
11 Correct 84 ms 8424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 12 ms 1404 KB Output is correct
5 Correct 22 ms 2292 KB Output is correct
6 Correct 66 ms 4436 KB Output is correct
7 Correct 130 ms 8552 KB Output is correct
8 Correct 112 ms 8644 KB Output is correct
9 Correct 108 ms 8524 KB Output is correct
10 Correct 83 ms 8420 KB Output is correct
11 Correct 84 ms 8424 KB Output is correct
12 Correct 35 ms 2420 KB Output is correct
13 Correct 84 ms 6968 KB Output is correct
14 Correct 135 ms 8684 KB Output is correct
15 Correct 110 ms 8604 KB Output is correct
16 Correct 115 ms 8424 KB Output is correct
17 Correct 103 ms 8556 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 12 ms 1404 KB Output is correct
12 Correct 22 ms 2292 KB Output is correct
13 Correct 66 ms 4436 KB Output is correct
14 Correct 130 ms 8552 KB Output is correct
15 Correct 112 ms 8644 KB Output is correct
16 Correct 108 ms 8524 KB Output is correct
17 Correct 83 ms 8420 KB Output is correct
18 Correct 84 ms 8424 KB Output is correct
19 Correct 35 ms 2420 KB Output is correct
20 Correct 84 ms 6968 KB Output is correct
21 Correct 135 ms 8684 KB Output is correct
22 Correct 110 ms 8604 KB Output is correct
23 Correct 115 ms 8424 KB Output is correct
24 Correct 103 ms 8556 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 380 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 48 ms 2416 KB Output is correct
33 Correct 116 ms 6888 KB Output is correct
34 Correct 200 ms 8516 KB Output is correct
35 Correct 179 ms 8600 KB Output is correct
36 Correct 121 ms 8544 KB Output is correct
37 Correct 183 ms 8556 KB Output is correct
38 Correct 116 ms 8428 KB Output is correct
39 Correct 121 ms 8164 KB Output is correct
40 Correct 113 ms 8572 KB Output is correct
41 Correct 112 ms 8552 KB Output is correct
42 Correct 116 ms 8552 KB Output is correct
43 Correct 123 ms 8684 KB Output is correct
44 Correct 147 ms 8424 KB Output is correct
45 Correct 103 ms 8424 KB Output is correct
46 Correct 119 ms 7660 KB Output is correct
47 Correct 2 ms 376 KB Output is correct