#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |