39912023-03-07 18:56:39horvathabelLeggyorsabb pénzkeresés (50)cpp17Accepted 50/5032ms5636 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, p;
	cin>>n>>p;
	vector<int> v; 
	for (int i=0; i<n;i++) {
		int x;
		cin>>x; 
		v.push_back(x);
	}
	int i=0,j=0;
	int ossz=0; 
	int ans=1000001;
	while (i<=n && j<=n){
		if (ossz<p){
			ossz+=v[j];
			j++;
		}
		if (ossz>=p){
			if (j-i<ans) ans=j-i;
			ossz-=v[i];
			i++;
			
		}
	}
	cout<<ans; 
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1684 KiB
2Accepted0/032ms3056 KiB
3Accepted2/23ms2152 KiB
4Accepted2/23ms2272 KiB
5Accepted2/23ms2524 KiB
6Accepted2/24ms2704 KiB
7Accepted2/24ms2672 KiB
8Accepted2/26ms2936 KiB
9Accepted2/24ms3212 KiB
10Accepted2/24ms3096 KiB
11Accepted2/232ms4264 KiB
12Accepted2/232ms4332 KiB
13Accepted2/232ms4424 KiB
14Accepted2/230ms4488 KiB
15Accepted2/232ms4468 KiB
16Accepted2/232ms4688 KiB
17Accepted2/232ms4760 KiB
18Accepted2/232ms5036 KiB
19Accepted2/232ms5008 KiB
20Accepted2/232ms5124 KiB
21Accepted2/232ms5224 KiB
22Accepted2/232ms5340 KiB
23Accepted2/232ms5424 KiB
24Accepted2/230ms5636 KiB
25Accepted2/230ms5488 KiB
26Accepted2/230ms5492 KiB
27Accepted2/230ms5488 KiB