This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
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... |