Submission #1279501

#TimeUsernameProblemLanguageResultExecution timeMemory
1279501muhammad-ahmadAirplane (NOI23_airplane)C++20
22 / 100
56 ms3536 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

signed main(){
	int n, m; cin >> n >> m;
	int alt = 0, ans = n - 1;
	int a[n + 1];
	int mx[n + 1];
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	mx[n] = 0;
	for (int i = n - 1; i >= 1; i--){
		mx[i] = max(mx[i + 1], a[i]);
	}
	for (int i = 1; i < n; i++){
		if (mx[i + 1] > alt) alt++;
		if (mx[i + 1] < alt) alt--;
		if (a[i + 1] > alt){
			if (a[i + 1] > alt){
				ans += a[i + 1] - alt;
				alt = a[i + 1];
			}
		}
	}
	
	cout << ans + alt << endl;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...