Submission #477098

# Submission time Handle Problem Language Result Execution time Memory
477098 2021-09-30T09:42:32 Z dsyz Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    ll N,M;
    cin>>N>>M;
    ll arr[N + 1];
  	ll arr2[N + 1];
    memset(arr,0,sizeof(arr));
  	memset(arr2,0,sizeof(arr2));
    for(ll i = 1;i <= N;i++){
		cin>>arr[i];
      	cin>>arr2[i];
	}
	ll sum = 0;
	for(ll i = 1;i <= N;i++){
		if(arr[i] > arr[i - 1] + M){
			arr[i] = arr[i - 1] + M;
			sum++;
		}else{
			if((i < N - 1 && arr[i] + M < arr[i + 1] && arr[i - 1] + M + M >= arr[i + 1])){
				arr[i] = arr[i - 1] + M + M;
				sum++;
			}
		}
	}
  	ll sum2 = 0;
	for(ll i = 1;i <= N;i++){
		if(arr2[i] > arr2[i - 1] + M){
			arr2[i] = arr2[i - 1] + M;
			sum2++;
		}else{
			if((i < N - 1 && arr2[i] + M < arr2[i + 1] && arr2[i - 1] + M + M >= arr2[i + 1]) ||
			(i < N - 2 && arr2[i + 1] + M < arr2[i + 2] && arr2[i - 1] + M + M + M >= arr2[i + 2])){
				arr2[i] = arr2[i - 1] + M + M;
				sum2++;
			}
		}
	}
	cout<<min(sum,sum2)<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -