Submission #531116

# Submission time Handle Problem Language Result Execution time Memory
531116 2022-02-27T19:08:56 Z Vladth11 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
376 ms 15276 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;

const ll NMAX = 500001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll nr_of_bits = 21;

int n;
ll v[NMAX], a, b;

int main() {
    //ifstream cin("niceset.in");
    //ofstream cout("niceset.out");
    int i;
    cin >> n;
    for(i = 1; i <= n; i++){
        cin >> a >> b;
        a -= b;
        v[i] = a;
        v[i] += v[i - 1];
    }
    ll sol = 0;
    priority_queue <ll> pq;
    for(i = 1; i <= n; i++){
        if(v[i] < 0){
            sol += -v[i];
            v[i] = 0;
        }
        if(v[i] > v[n]){
            sol += (v[i] - v[n]);
            v[i] = v[n];
        }
        pq.push(v[i]);
        pq.push(v[i]);
        sol += (v[n] - v[i]);
        sol -= (v[n] - pq.top());
        pq.pop();
    }
    cout << sol;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 20 ms 1608 KB Output is correct
5 Correct 40 ms 2772 KB Output is correct
6 Correct 144 ms 7808 KB Output is correct
7 Correct 309 ms 15276 KB Output is correct
8 Correct 245 ms 13232 KB Output is correct
9 Correct 266 ms 12848 KB Output is correct
10 Correct 160 ms 10308 KB Output is correct
11 Correct 161 ms 10340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 20 ms 1608 KB Output is correct
5 Correct 40 ms 2772 KB Output is correct
6 Correct 144 ms 7808 KB Output is correct
7 Correct 309 ms 15276 KB Output is correct
8 Correct 245 ms 13232 KB Output is correct
9 Correct 266 ms 12848 KB Output is correct
10 Correct 160 ms 10308 KB Output is correct
11 Correct 161 ms 10340 KB Output is correct
12 Correct 94 ms 4084 KB Output is correct
13 Correct 188 ms 10936 KB Output is correct
14 Correct 300 ms 15192 KB Output is correct
15 Correct 269 ms 13240 KB Output is correct
16 Correct 227 ms 12600 KB Output is correct
17 Correct 162 ms 10424 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 312 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 312 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 3 ms 308 KB Output is correct
14 Correct 3 ms 316 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 2 ms 288 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 312 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 20 ms 1608 KB Output is correct
12 Correct 40 ms 2772 KB Output is correct
13 Correct 144 ms 7808 KB Output is correct
14 Correct 309 ms 15276 KB Output is correct
15 Correct 245 ms 13232 KB Output is correct
16 Correct 266 ms 12848 KB Output is correct
17 Correct 160 ms 10308 KB Output is correct
18 Correct 161 ms 10340 KB Output is correct
19 Correct 94 ms 4084 KB Output is correct
20 Correct 188 ms 10936 KB Output is correct
21 Correct 300 ms 15192 KB Output is correct
22 Correct 269 ms 13240 KB Output is correct
23 Correct 227 ms 12600 KB Output is correct
24 Correct 162 ms 10424 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 3 ms 308 KB Output is correct
27 Correct 3 ms 316 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 288 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 100 ms 4104 KB Output is correct
34 Correct 194 ms 10884 KB Output is correct
35 Correct 376 ms 15116 KB Output is correct
36 Correct 312 ms 12704 KB Output is correct
37 Correct 276 ms 13292 KB Output is correct
38 Correct 375 ms 15160 KB Output is correct
39 Correct 194 ms 11260 KB Output is correct
40 Correct 209 ms 10804 KB Output is correct
41 Correct 195 ms 10440 KB Output is correct
42 Correct 164 ms 10332 KB Output is correct
43 Correct 170 ms 10340 KB Output is correct
44 Correct 183 ms 10404 KB Output is correct
45 Correct 315 ms 15136 KB Output is correct
46 Correct 192 ms 10728 KB Output is correct
47 Correct 185 ms 10168 KB Output is correct