44252023-03-27 19:10:32KevinLeghosszabb nyaralás (75 pont)cpp17Wrong answer 58/7527ms4476 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, p;
	cin >> n;
	cin >> p;
	vector<int> a(n);
	for (int i=0; i<n ;i++)
		cin >> a[i];
	
	int elso=0;
	int utolso=-1;
	int osszeg=0;
	int megoldas=0;
	while (utolso < n){
		while (a[utolso+1]>p&&utolso<n){
			utolso++;
			elso=utolso+1;
		}
		utolso++;
		osszeg=osszeg+a[utolso];
		while (osszeg>p){
			osszeg=osszeg-a[elso];
			elso++;
		}
		if (utolso-elso+1>megoldas)
			megoldas=utolso-elso+1;
	}
	cout << megoldas;
}
SubtaskSumTestVerdictTimeMemory
base58/75
1Accepted0/03ms1812 KiB
2Accepted0/027ms2712 KiB
3Accepted3/33ms2216 KiB
4Wrong answer0/32ms2336 KiB
5Accepted3/33ms2528 KiB
6Accepted3/33ms2768 KiB
7Wrong answer0/33ms2952 KiB
8Wrong answer0/43ms3164 KiB
9Accepted4/43ms3376 KiB
10Accepted5/53ms3500 KiB
11Accepted5/54ms3788 KiB
12Accepted5/54ms3740 KiB
13Wrong answer0/719ms4412 KiB
14Accepted7/723ms4376 KiB
15Accepted7/727ms4384 KiB
16Accepted8/826ms4376 KiB
17Accepted8/827ms4476 KiB