83842024-01-15 11:20:02GervidLádapakolás raktárban (50)cpp17Accepted 50/5052ms12332 KiB
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
	int n, m, i, last, begin, out = 0, sum;
	cin >> n >> m;

	vector<int> boxes(n);

	for (i = 0; i < n; i++)
	{
		cin >> boxes[i];
	}

	i = 1, last = boxes[0], sum = boxes[0], begin = 0;

	set<int> stacksizes;
	stacksizes.insert(boxes[0]);

	while (i < n)
	{
		while (i < n && boxes[i] > last && m >= sum + boxes[i])//sum nem jó
		{
			stacksizes.insert(boxes[i]);
			last = boxes[i];
			sum += boxes[i];
			i++;
		}

		while (i < n && last > boxes[i] && !stacksizes.count(boxes[i]) && m >= sum + boxes[i])
		{
			last = boxes[i];
			sum += boxes[i];
			stacksizes.insert(boxes[i]);
			i++;
		}

		out += i - begin - 1;

		if (i < n)
		{
			begin = i;
			sum = boxes[i];
			stacksizes = { boxes[i] };
			last = boxes[i];
			i++;
		}
	}

	cout << out;
}
//12 16
//1 3 5 4 2 6 8 7 6 5 3 4
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2084 KiB
2Accepted0/06ms2324 KiB
3Accepted2/23ms2320 KiB
4Accepted2/23ms2400 KiB
5Accepted2/23ms2536 KiB
6Accepted2/23ms2768 KiB
7Accepted2/23ms2904 KiB
8Accepted2/23ms3028 KiB
9Accepted3/33ms3184 KiB
10Accepted2/23ms3172 KiB
11Accepted2/23ms3536 KiB
12Accepted2/23ms3608 KiB
13Accepted3/34ms3616 KiB
14Accepted3/34ms3752 KiB
15Accepted3/36ms3980 KiB
16Accepted2/232ms5012 KiB
17Accepted3/343ms5556 KiB
18Accepted3/352ms6492 KiB
19Accepted3/337ms7084 KiB
20Accepted3/350ms10824 KiB
21Accepted3/345ms11200 KiB
22Accepted3/348ms12332 KiB