Submission #238596

# Submission time Handle Problem Language Result Execution time Memory
238596 2020-06-12T06:24:32 Z DodgeBallMan Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
218 ms 12008 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 10;
int n;
long long c[N], ans;
priority_queue<long long> q;

int main()
{
    scanf("%d",&n);
    for( int i = 1 ; i <= n ; i++ ) {
        long long a, b;
        scanf("%lld %lld",&a,&b);
        c[i] = c[i-1] + a - b;
    }
    for( int i = 1 ; i <= n ; i++ ) {
        if( c[i] > c[n] ) ans += c[i] - c[n], c[i] = c[n];
        if( c[i] < 0 ) ans -= c[i], c[i] = 0;
        q.emplace( c[i] );
        if( q.top() != c[i] ) {
            ans += q.top() - c[i];
            q.pop();
            q.emplace( c[i] );
        }
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
bulves.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 16 ms 1660 KB Output is correct
5 Correct 27 ms 2936 KB Output is correct
6 Correct 77 ms 6252 KB Output is correct
7 Correct 153 ms 12008 KB Output is correct
8 Correct 117 ms 11188 KB Output is correct
9 Correct 127 ms 11624 KB Output is correct
10 Correct 104 ms 10472 KB Output is correct
11 Correct 113 ms 10472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 16 ms 1660 KB Output is correct
5 Correct 27 ms 2936 KB Output is correct
6 Correct 77 ms 6252 KB Output is correct
7 Correct 153 ms 12008 KB Output is correct
8 Correct 117 ms 11188 KB Output is correct
9 Correct 127 ms 11624 KB Output is correct
10 Correct 104 ms 10472 KB Output is correct
11 Correct 113 ms 10472 KB Output is correct
12 Correct 42 ms 4088 KB Output is correct
13 Correct 106 ms 10128 KB Output is correct
14 Correct 160 ms 11624 KB Output is correct
15 Correct 114 ms 11752 KB Output is correct
16 Correct 140 ms 11616 KB Output is correct
17 Correct 115 ms 10408 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 16 ms 1660 KB Output is correct
12 Correct 27 ms 2936 KB Output is correct
13 Correct 77 ms 6252 KB Output is correct
14 Correct 153 ms 12008 KB Output is correct
15 Correct 117 ms 11188 KB Output is correct
16 Correct 127 ms 11624 KB Output is correct
17 Correct 104 ms 10472 KB Output is correct
18 Correct 113 ms 10472 KB Output is correct
19 Correct 42 ms 4088 KB Output is correct
20 Correct 106 ms 10128 KB Output is correct
21 Correct 160 ms 11624 KB Output is correct
22 Correct 114 ms 11752 KB Output is correct
23 Correct 140 ms 11616 KB Output is correct
24 Correct 115 ms 10408 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 7 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 6 ms 384 KB Output is correct
32 Correct 56 ms 4208 KB Output is correct
33 Correct 131 ms 10168 KB Output is correct
34 Correct 214 ms 11624 KB Output is correct
35 Correct 193 ms 11620 KB Output is correct
36 Correct 115 ms 11624 KB Output is correct
37 Correct 218 ms 11752 KB Output is correct
38 Correct 122 ms 11544 KB Output is correct
39 Correct 126 ms 10984 KB Output is correct
40 Correct 145 ms 10472 KB Output is correct
41 Correct 132 ms 10472 KB Output is correct
42 Correct 136 ms 10516 KB Output is correct
43 Correct 136 ms 10600 KB Output is correct
44 Correct 171 ms 11752 KB Output is correct
45 Correct 130 ms 10728 KB Output is correct
46 Correct 135 ms 10468 KB Output is correct
47 Correct 5 ms 384 KB Output is correct