10002022-02-20 19:27:09kidesoLeggyorsabb pénzkeresés (50)cpp14Accepted 50/5028ms11400 KiB
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main()
{
	int N, P;
	cin >> N >> P;
	
	vector <int> x(N);

	for (auto& e : x) cin >> e;

	int h = INT_MAX;

	int a = 0, b = 0, s = x[0];
	while (b < N) {
		if (a == b) {
			++b;
			if (b < N) s += x[b];
			if (s >= P) h = min(h, b - a + 1);
		}
		else {
			if (s < P) {
				++b;
				if (b < N) s += x[b];
			}
			else {
				h = min(h, b - a + 1);
				s -= x[a];
				++a;
			}
		}
	}

	cout << h << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1736 KiB
2Accepted0/026ms3036 KiB
3Accepted2/21ms2324 KiB
4Accepted2/21ms2332 KiB
5Accepted2/21ms2336 KiB
6Accepted2/24ms2380 KiB
7Accepted2/23ms2428 KiB
8Accepted2/24ms2476 KiB
9Accepted2/23ms2524 KiB
10Accepted2/24ms2572 KiB
11Accepted2/227ms3696 KiB
12Accepted2/226ms4172 KiB
13Accepted2/228ms4656 KiB
14Accepted2/226ms5140 KiB
15Accepted2/226ms5624 KiB
16Accepted2/226ms6108 KiB
17Accepted2/227ms6580 KiB
18Accepted2/227ms7060 KiB
19Accepted2/228ms7548 KiB
20Accepted2/228ms8028 KiB
21Accepted2/227ms8508 KiB
22Accepted2/228ms9116 KiB
23Accepted2/227ms9476 KiB
24Accepted2/227ms9960 KiB
25Accepted2/227ms10436 KiB
26Accepted2/228ms10920 KiB
27Accepted2/227ms11400 KiB