Submission #489682

# Submission time Handle Problem Language Result Execution time Memory
489682 2021-11-23T19:27:18 Z andrii Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
131 ms 15208 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pll pair<ll, ll>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> yree;
const ld inf = 0x3fff3fff3fff3fff;
const ll N = 5e5+18;

ll a[N];

signed main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    for(ll i = 0;i<n;i++){
        ll u, v;
        cin >> u >> v;
        a[i]=u-v;
        if(i) a[i]+=a[i-1];
    }
    priority_queue<ll> pq;
    ll res=0;
    for(ll i = 0;i+1<n;i++){
        if(a[i]<0) res+=-a[i], a[i]=0;
        if(a[i]>a[n-1]) res+=a[i]-a[n-1], a[i]=a[n-1];
        pq.push(a[i]);
        if(pq.top()>a[i]){
            res+=pq.top()-a[i];
            pq.pop();
            pq.push(a[i]);
        }
    }
    cout<<res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 6 ms 1616 KB Output is correct
5 Correct 12 ms 2892 KB Output is correct
6 Correct 40 ms 7744 KB Output is correct
7 Correct 80 ms 15208 KB Output is correct
8 Correct 69 ms 13264 KB Output is correct
9 Correct 64 ms 12616 KB Output is correct
10 Correct 47 ms 10324 KB Output is correct
11 Correct 48 ms 10300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 6 ms 1616 KB Output is correct
5 Correct 12 ms 2892 KB Output is correct
6 Correct 40 ms 7744 KB Output is correct
7 Correct 80 ms 15208 KB Output is correct
8 Correct 69 ms 13264 KB Output is correct
9 Correct 64 ms 12616 KB Output is correct
10 Correct 47 ms 10324 KB Output is correct
11 Correct 48 ms 10300 KB Output is correct
12 Correct 21 ms 4084 KB Output is correct
13 Correct 53 ms 10960 KB Output is correct
14 Correct 81 ms 15120 KB Output is correct
15 Correct 65 ms 13348 KB Output is correct
16 Correct 69 ms 12652 KB Output is correct
17 Correct 59 ms 10316 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 6 ms 1616 KB Output is correct
12 Correct 12 ms 2892 KB Output is correct
13 Correct 40 ms 7744 KB Output is correct
14 Correct 80 ms 15208 KB Output is correct
15 Correct 69 ms 13264 KB Output is correct
16 Correct 64 ms 12616 KB Output is correct
17 Correct 47 ms 10324 KB Output is correct
18 Correct 48 ms 10300 KB Output is correct
19 Correct 21 ms 4084 KB Output is correct
20 Correct 53 ms 10960 KB Output is correct
21 Correct 81 ms 15120 KB Output is correct
22 Correct 65 ms 13348 KB Output is correct
23 Correct 69 ms 12652 KB Output is correct
24 Correct 59 ms 10316 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 31 ms 4032 KB Output is correct
34 Correct 77 ms 10824 KB Output is correct
35 Correct 131 ms 15184 KB Output is correct
36 Correct 115 ms 12692 KB Output is correct
37 Correct 70 ms 13244 KB Output is correct
38 Correct 120 ms 15152 KB Output is correct
39 Correct 74 ms 11348 KB Output is correct
40 Correct 77 ms 10936 KB Output is correct
41 Correct 64 ms 10352 KB Output is correct
42 Correct 66 ms 10400 KB Output is correct
43 Correct 69 ms 10308 KB Output is correct
44 Correct 68 ms 10420 KB Output is correct
45 Correct 88 ms 15092 KB Output is correct
46 Correct 67 ms 10632 KB Output is correct
47 Correct 77 ms 10172 KB Output is correct