90202024-02-12 11:04:41IgnácLeghosszabb nyaralás (75 pont)cpp17Accepted 75/7527ms6132 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, p;
	cin >> n >> p;
	int j = 0, maxi = 0;
	long long sum = 0;
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		b[i] = a;
		sum += a;
		while (sum > p) {
			sum -= b[j];
			j++;
		}

		if (i - j + 1 > maxi) maxi = i - j + 1;
	}

	cout << maxi;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1816 KiB
2Accepted0/027ms3096 KiB
3Accepted3/33ms2728 KiB
4Accepted3/33ms2980 KiB
5Accepted3/33ms3016 KiB
6Accepted3/32ms3020 KiB
7Accepted3/33ms3268 KiB
8Accepted4/43ms3508 KiB
9Accepted4/43ms3508 KiB
10Accepted5/53ms3768 KiB
11Accepted5/54ms3976 KiB
12Accepted5/54ms3956 KiB
13Accepted7/719ms4624 KiB
14Accepted7/724ms4944 KiB
15Accepted7/727ms5416 KiB
16Accepted8/826ms5664 KiB
17Accepted8/827ms6132 KiB