Submission #713644

# Submission time Handle Problem Language Result Execution time Memory
713644 2023-03-22T17:58:23 Z EqualTurtle Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
149 ms 15320 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MAXN = 5e5 + 7;

long long tab[MAXN];
int n;
long long res;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	priority_queue<long long> pq;

	for (int i = 1; i <= n; i++)
    {
		long long a;
        cin >> tab[i] >> a;
        tab[i] += tab[i - 1] - a;
	}

	for (int i = 1; i <= n; i++)
    {
        // modyfikacja zeby wartosci byly z przedzialu (0, #nawozow - #ziemniakow)
		if (tab[i] < 0) 
        {
			res -= tab[i];
			tab[i] = 0;
		}
		else if (tab[i] > tab[n])
        {
			res += tab[i] - tab[n];
			tab[i] = tab[n];
		}

        // a dalej klasyczna sztuczka
		pq.push(tab[i]);
		pq.push(tab[i]);
		res += pq.top() - tab[i];
		pq.pop();
	}

	cout << res << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 1320 KB Output is correct
5 Correct 15 ms 2196 KB Output is correct
6 Correct 49 ms 4348 KB Output is correct
7 Correct 107 ms 8480 KB Output is correct
8 Correct 87 ms 8364 KB Output is correct
9 Correct 98 ms 8360 KB Output is correct
10 Correct 74 ms 8456 KB Output is correct
11 Correct 68 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 1320 KB Output is correct
5 Correct 15 ms 2196 KB Output is correct
6 Correct 49 ms 4348 KB Output is correct
7 Correct 107 ms 8480 KB Output is correct
8 Correct 87 ms 8364 KB Output is correct
9 Correct 98 ms 8360 KB Output is correct
10 Correct 74 ms 8456 KB Output is correct
11 Correct 68 ms 8432 KB Output is correct
12 Correct 30 ms 2376 KB Output is correct
13 Correct 76 ms 10936 KB Output is correct
14 Correct 126 ms 15320 KB Output is correct
15 Correct 98 ms 13312 KB Output is correct
16 Correct 97 ms 12692 KB Output is correct
17 Correct 78 ms 10316 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 7 ms 1320 KB Output is correct
12 Correct 15 ms 2196 KB Output is correct
13 Correct 49 ms 4348 KB Output is correct
14 Correct 107 ms 8480 KB Output is correct
15 Correct 87 ms 8364 KB Output is correct
16 Correct 98 ms 8360 KB Output is correct
17 Correct 74 ms 8456 KB Output is correct
18 Correct 68 ms 8432 KB Output is correct
19 Correct 30 ms 2376 KB Output is correct
20 Correct 76 ms 10936 KB Output is correct
21 Correct 126 ms 15320 KB Output is correct
22 Correct 98 ms 13312 KB Output is correct
23 Correct 97 ms 12692 KB Output is correct
24 Correct 78 ms 10316 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 37 ms 4116 KB Output is correct
34 Correct 80 ms 10952 KB Output is correct
35 Correct 149 ms 15200 KB Output is correct
36 Correct 122 ms 12788 KB Output is correct
37 Correct 118 ms 13344 KB Output is correct
38 Correct 129 ms 15224 KB Output is correct
39 Correct 97 ms 11324 KB Output is correct
40 Correct 98 ms 10956 KB Output is correct
41 Correct 88 ms 10432 KB Output is correct
42 Correct 83 ms 10388 KB Output is correct
43 Correct 97 ms 10372 KB Output is correct
44 Correct 83 ms 10388 KB Output is correct
45 Correct 122 ms 15168 KB Output is correct
46 Correct 106 ms 10664 KB Output is correct
47 Correct 86 ms 10192 KB Output is correct