42512023-03-19 17:25:21horvathabelLádapakolás raktárban (50)cpp17Accepted 50/5052ms8596 KiB
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin>>n>>k;
vector<int> m;
for (int i=0;i<n;i++){
	int x;
	cin>>x;
	m.push_back(x);
}
int sum=m[0];
set<int> s;
int ans=0; 
s.insert(m[0]); 
bool voltefopont=false; 
for (int i=1; i<n;i++){
	if (m[i]<m[i-1] && !voltefopont) voltefopont=true; 
	if (voltefopont && m[i]>m[i-1] or (sum+m[i]>k or s.find(m[i])!=s.end())){
		sum=0; 
		voltefopont=false;
		ans++;
		s.clear(); 
	}  
	sum+=m[i];
	s.insert(m[i]);
}
cout<<n-ans-1; 
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/04ms2292 KiB
3Accepted2/23ms2212 KiB
4Accepted2/23ms2432 KiB
5Accepted2/23ms2644 KiB
6Accepted2/23ms2880 KiB
7Accepted2/22ms2944 KiB
8Accepted2/22ms2936 KiB
9Accepted3/33ms2952 KiB
10Accepted2/23ms3076 KiB
11Accepted2/23ms3164 KiB
12Accepted2/23ms3316 KiB
13Accepted3/34ms3552 KiB
14Accepted3/34ms3828 KiB
15Accepted3/36ms4040 KiB
16Accepted2/232ms5004 KiB
17Accepted3/341ms5008 KiB
18Accepted3/350ms5012 KiB
19Accepted3/337ms5096 KiB
20Accepted3/352ms8080 KiB
21Accepted3/346ms8076 KiB
22Accepted3/348ms8596 KiB