Submission #973139

# Submission time Handle Problem Language Result Execution time Memory
973139 2024-05-01T14:14:48 Z hihihah Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
145 ms 20928 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()
#define pii pair<int, int>

int n;
int a[500009];
int b[500009];
int64_t pre[500009];

void hihihah()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> a[i] >> b[i];

    for(int i = 1; i <= n; i ++)
    {
        pre[i] = pre[i - 1] + a[i] - b[i];
    }

    priority_queue<int64_t> p;

    int64_t ans = 0;
    p.push(0);

    for(int i = 1; i <= n; i ++)
    {
        if(pre[i] < 0)
        {
            ans += -pre[i];
            pre[i] = 0;
        }
        if(p.top() > pre[i]) ans += p.top() - pre[i];
        p.push(pre[i]);
        p.push(pre[i]);
        p.pop();
    }

    while(p.top() > pre[n])
    {
        ans += p.top() - pre[n];
        p.pop();
    }

    cout << ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #define orz "mo"
    if(fopen(orz".inp", "r"))
    {
        freopen(orz".inp", "r", stdin);
//        freopen(orz".out", "w", stdout);
    }

    int t = 1;
//    cin >> t;
    while(t --)
    {
        hihihah();
    }
    return 0;
}

Compilation message

bulves.cpp: In function 'int32_t main()':
bulves.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(orz".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 14 ms 7388 KB Output is correct
5 Correct 26 ms 7724 KB Output is correct
6 Correct 89 ms 9292 KB Output is correct
7 Correct 94 ms 12656 KB Output is correct
8 Correct 142 ms 12744 KB Output is correct
9 Correct 98 ms 13112 KB Output is correct
10 Correct 88 ms 12752 KB Output is correct
11 Correct 104 ms 13396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 14 ms 7388 KB Output is correct
5 Correct 26 ms 7724 KB Output is correct
6 Correct 89 ms 9292 KB Output is correct
7 Correct 94 ms 12656 KB Output is correct
8 Correct 142 ms 12744 KB Output is correct
9 Correct 98 ms 13112 KB Output is correct
10 Correct 88 ms 12752 KB Output is correct
11 Correct 104 ms 13396 KB Output is correct
12 Correct 39 ms 7892 KB Output is correct
13 Correct 100 ms 14276 KB Output is correct
14 Correct 98 ms 17404 KB Output is correct
15 Correct 145 ms 17192 KB Output is correct
16 Correct 145 ms 16400 KB Output is correct
17 Correct 69 ms 14280 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 14 ms 7388 KB Output is correct
12 Correct 26 ms 7724 KB Output is correct
13 Correct 89 ms 9292 KB Output is correct
14 Correct 94 ms 12656 KB Output is correct
15 Correct 142 ms 12744 KB Output is correct
16 Correct 98 ms 13112 KB Output is correct
17 Correct 88 ms 12752 KB Output is correct
18 Correct 104 ms 13396 KB Output is correct
19 Correct 39 ms 7892 KB Output is correct
20 Correct 100 ms 14276 KB Output is correct
21 Correct 98 ms 17404 KB Output is correct
22 Correct 145 ms 17192 KB Output is correct
23 Correct 145 ms 16400 KB Output is correct
24 Correct 69 ms 14280 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4696 KB Output is correct
31 Correct 1 ms 4572 KB Output is correct
32 Correct 1 ms 4440 KB Output is correct
33 Correct 29 ms 9436 KB Output is correct
34 Correct 69 ms 16844 KB Output is correct
35 Correct 122 ms 20928 KB Output is correct
36 Correct 106 ms 17884 KB Output is correct
37 Correct 130 ms 17588 KB Output is correct
38 Correct 126 ms 19916 KB Output is correct
39 Correct 75 ms 16336 KB Output is correct
40 Correct 91 ms 16852 KB Output is correct
41 Correct 72 ms 14532 KB Output is correct
42 Correct 90 ms 14800 KB Output is correct
43 Correct 72 ms 15808 KB Output is correct
44 Correct 74 ms 15652 KB Output is correct
45 Correct 131 ms 19920 KB Output is correct
46 Correct 97 ms 15536 KB Output is correct
47 Correct 77 ms 16572 KB Output is correct