11394 | 2024-09-05 14:07:50 | Gervid | Szemetessor | cpp17 | Accepted 100/100 | 136ms | 14480 KiB |
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
iostream::sync_with_stdio(0);
cin.tie(0);
long long n, k, i, t, q, j;
cin >> n >> k;
vector<long long> cap(n), current(n);
for (i = 0; i < n; i++)
{
cin >> cap[i];
}
vector<vector<long long>> trash(n);
for (i = 0; i < k; i++)
{
cin >> t >> q;
trash[t].push_back(q);
}
long long ans = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < trash[i].size(); j++)
{
if (j == trash[i].size() - 1)
{
ans += cap[i] - current[i] - trash[i][j];
}
else
{
if (cap[i] < current[i] + trash[i][j] + trash[i][j+1])
{
ans += cap[i] - current[i] - trash[i][j];
current[i] = 0;
}
else
{
current[i] += trash[i][j];
}
}
}
}
cout << ans << '\n';
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 2ms | 360 KiB | ||||
2 | Accepted | 2ms | 504 KiB | ||||
subtask2 | 17/17 | ||||||
3 | Accepted | 2ms | 316 KiB | ||||
4 | Accepted | 3ms | 416 KiB | ||||
5 | Accepted | 3ms | 528 KiB | ||||
6 | Accepted | 3ms | 636 KiB | ||||
7 | Accepted | 2ms | 360 KiB | ||||
8 | Accepted | 3ms | 296 KiB | ||||
9 | Accepted | 3ms | 360 KiB | ||||
10 | Accepted | 3ms | 360 KiB | ||||
11 | Accepted | 3ms | 504 KiB | ||||
subtask3 | 25/25 | ||||||
12 | Accepted | 46ms | 2664 KiB | ||||
13 | Accepted | 48ms | 3324 KiB | ||||
14 | Accepted | 50ms | 3432 KiB | ||||
15 | Accepted | 57ms | 3332 KiB | ||||
16 | Accepted | 61ms | 3348 KiB | ||||
17 | Accepted | 105ms | 8564 KiB | ||||
18 | Accepted | 136ms | 14480 KiB | ||||
19 | Accepted | 120ms | 14480 KiB | ||||
20 | Accepted | 127ms | 14440 KiB | ||||
subtask4 | 20/20 | ||||||
21 | Accepted | 54ms | 3432 KiB | ||||
22 | Accepted | 74ms | 5352 KiB | ||||
23 | Accepted | 54ms | 3452 KiB | ||||
24 | Accepted | 68ms | 4344 KiB | ||||
25 | Accepted | 59ms | 3304 KiB | ||||
26 | Accepted | 96ms | 7676 KiB | ||||
27 | Accepted | 129ms | 11908 KiB | ||||
28 | Accepted | 118ms | 12192 KiB | ||||
29 | Accepted | 120ms | 12008 KiB | ||||
30 | Accepted | 114ms | 12280 KiB | ||||
subtask5 | 38/38 | ||||||
31 | Accepted | 2ms | 360 KiB | ||||
32 | Accepted | 3ms | 656 KiB | ||||
33 | Accepted | 3ms | 536 KiB | ||||
34 | Accepted | 3ms | 360 KiB | ||||
35 | Accepted | 7ms | 888 KiB | ||||
36 | Accepted | 54ms | 3088 KiB | ||||
37 | Accepted | 126ms | 11472 KiB | ||||
38 | Accepted | 112ms | 11112 KiB | ||||
39 | Accepted | 128ms | 11496 KiB | ||||
40 | Accepted | 116ms | 11804 KiB | ||||
41 | Accepted | 130ms | 12392 KiB | ||||
42 | Accepted | 131ms | 12012 KiB |