#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin>>n>>m;
vector<int> a(n);
for(int i=0; i<n; i++) cin>>a[i];
for(int i=0; i<m; i++) {
int tmp;
cin>>tmp>>tmp;
}
int cur = 0, ans = 0;
vector<int> sufmax(n);
sufmax[n-1] = a[n-1];
for(int i=n-2; i>0; i--) sufmax[i] = max(sufmax[i+1], a[i]);
for(int i=0; i<n-1; i++) {
if(cur + 1 < a[i+1]) {
ans += a[i+1]-1-cur;
cur += a[i+1]-1-cur;
}
if(sufmax[i] > cur) {
cur++;
ans++;
}
else if(sufmax[i] < cur) {
cur--;
ans++;
}
else ans++;
}
ans += max(1, cur);
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
109 ms |
1976 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
109 ms |
1976 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |