#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
vector<vector<int>> G;
vector<int> v(n); for(int& i : v) cin>>i;
int trash;
while(m--) cin>>trash>>trash;
vector<int> suf(n+1); suf[n] = 0;
for(int i = n-1; i>=0 ; i--) suf[i] = max(v[i], suf[i+1]);
int h = 0;
int ans = 0;
for(int i = 0; i<n; i++){
if(v[i] > h){
ans += v[i]-h; h = v[i]; // just go up
}
else if(h < suf[i]) h++;
else if(h > suf[i]) h--;
}
cout<<ans+n<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
34 ms |
6740 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
34 ms |
6740 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |