#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int32_t 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(1l, cur);
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
108 ms |
3544 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
108 ms |
3544 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |