Submission #1220727

#TimeUsernameProblemLanguageResultExecution timeMemory
1220727himorningRabbit Carrot (LMIO19_triusis)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N,M;
	if(!(cin>>N>>M)){
	    return 0;
	}
	vector<long long>a(N);
	for(int i=0; i<N; i++)cin>>a[i];
	const long long INF=LLONG_MAX/4;
	long long c0=0,h0=0,c1=INF,h1=0;
	for(int i=0; i<N; i++) {
		long long nc0=INF, nh0=0, nc1=INF, nh1=0;
		if(a[i]<=h0+M && c0<INF) {
			nc0=c0;
			nh0=a[i];
		}
		if(a[i]<=h1+M && c1<INF) {
			if(c1<nc0) {
				nc0=c1;
				nh0=a[i];
			}
		}
		if(c0<INF) {
			long long t=c0+1, ht=h0+M;
			if(t<nc1) {
				nc1=t;
				nh1=ht;
			}
		}
		if(c1<INF) {
			long long t=c1+1, ht=h1+M;
			if(t<nc1) {
				nc1=t;
				nh1=ht;
			}
		}
		c0=nc0;
		h0=nh0;
		c1=nc1;
		h1=nh1;
	}
	cout<<min(c0,c1);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...