113942024-09-05 14:07:50GervidSzemetessorcpp17Accepted 100/100136ms14480 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';
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms360 KiB
2Accepted2ms504 KiB
subtask217/17
3Accepted2ms316 KiB
4Accepted3ms416 KiB
5Accepted3ms528 KiB
6Accepted3ms636 KiB
7Accepted2ms360 KiB
8Accepted3ms296 KiB
9Accepted3ms360 KiB
10Accepted3ms360 KiB
11Accepted3ms504 KiB
subtask325/25
12Accepted46ms2664 KiB
13Accepted48ms3324 KiB
14Accepted50ms3432 KiB
15Accepted57ms3332 KiB
16Accepted61ms3348 KiB
17Accepted105ms8564 KiB
18Accepted136ms14480 KiB
19Accepted120ms14480 KiB
20Accepted127ms14440 KiB
subtask420/20
21Accepted54ms3432 KiB
22Accepted74ms5352 KiB
23Accepted54ms3452 KiB
24Accepted68ms4344 KiB
25Accepted59ms3304 KiB
26Accepted96ms7676 KiB
27Accepted129ms11908 KiB
28Accepted118ms12192 KiB
29Accepted120ms12008 KiB
30Accepted114ms12280 KiB
subtask538/38
31Accepted2ms360 KiB
32Accepted3ms656 KiB
33Accepted3ms536 KiB
34Accepted3ms360 KiB
35Accepted7ms888 KiB
36Accepted54ms3088 KiB
37Accepted126ms11472 KiB
38Accepted112ms11112 KiB
39Accepted128ms11496 KiB
40Accepted116ms11804 KiB
41Accepted130ms12392 KiB
42Accepted131ms12012 KiB