62352023-11-08 12:17:26EsVagySzemetessorcpp17Accepted 100/100256ms8332 KiB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	
	vector<int> c;
	vector<int> t;
	long int cost = 0;
	for (int i = 0; i < N; i++)
	{
		int next;
		cin >> next;
		c.push_back(next);
		t.push_back(0);
	}

	for (int i = 0; i < K; i++)
	{
		int index, trash;
		cin >> index >> trash;
		long int newTrash = t[index] + trash;
		if (newTrash > c[index])
		{
			cost += c[index] - t[index];
			t[index] = trash;
		}
		else
		{
			t[index] += trash;
		}
	}

	for (int i = 0; i < N; i++)
	{
		cost += t[i] == 0 ? 0 : c[i] - t[i];
	}

	cout << cost;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted3ms2004 KiB
subtask217/17
3Accepted3ms2212 KiB
4Accepted3ms2428 KiB
5Accepted3ms2648 KiB
6Accepted3ms2848 KiB
7Accepted2ms2932 KiB
8Accepted3ms3064 KiB
9Accepted3ms3304 KiB
10Accepted2ms3276 KiB
11Accepted2ms3156 KiB
subtask325/25
12Accepted122ms3284 KiB
13Accepted120ms3412 KiB
14Accepted135ms3504 KiB
15Accepted141ms3796 KiB
16Accepted153ms4236 KiB
17Accepted202ms5868 KiB
18Accepted252ms7644 KiB
19Accepted252ms7832 KiB
20Accepted252ms7928 KiB
subtask420/20
21Accepted126ms4928 KiB
22Accepted148ms5496 KiB
23Accepted128ms5232 KiB
24Accepted150ms5476 KiB
25Accepted135ms5180 KiB
26Accepted197ms6724 KiB
27Accepted247ms8056 KiB
28Accepted248ms7992 KiB
29Accepted250ms8064 KiB
30Accepted217ms8332 KiB
subtask538/38
31Accepted3ms4948 KiB
32Accepted3ms4948 KiB
33Accepted3ms5060 KiB
34Accepted3ms4952 KiB
35Accepted14ms5352 KiB
36Accepted142ms4852 KiB
37Accepted256ms8192 KiB
38Accepted254ms8192 KiB
39Accepted256ms8200 KiB
40Accepted254ms8200 KiB
41Accepted254ms8288 KiB
42Accepted254ms8200 KiB