Submission #1279490

#TimeUsernameProblemLanguageResultExecution timeMemory
1279490muhammad-ahmadAirplane (NOI23_airplane)C++20
0 / 100
28 ms572 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 lst; cin >> lst;
	for (int i = 2; i <= n; i++){
		int x; cin >> x;
		if (x  > alt){
			alt++;
			ans += x - alt;
			alt = x;
		}
		else if (x < alt){
			alt--;
			ans += alt - x;
			alt = x;
		}
	}
	cout << ans << 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...