#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int INF = LONG_LONG_MAX;
int32_t main(){
int n,m;cin>>n>>m;
vector<int> arr(n);
for (int i = 0; i < n; ++i)
{
cin>>arr[i];
}
vector<vector<int>> tree(n);
for (int i = 0; i < m; i++){
int u,v;cin>>u>>v;
tree[u-1].push_back(v-1);
tree[v-1].push_back(u-1);
}
vector<int> suff = arr;
for (int i = n-2; i >= 0; i--){
suff[i]=max(suff[i+1],suff[i]);
}
int crh = 0;
int ans = 0;
int maxind = 0;
for (int i = 0; i < n; ++i)
{
if (arr[i]>arr[maxind]) maxind=i;
}
for (int i = 0; i < maxind; i++){
ans++;
if (crh<arr[maxind]){
crh++;
if (crh<arr[i+1]){
ans+=arr[i+1]-crh;
crh=arr[i+1];
}
}
}
for (int i = maxind; i < n-1; i++){
if (crh>suff[i+1]) crh--;
ans++;
}
cout<<ans+crh<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
124 ms |
14508 KB |
Output is correct |
3 |
Correct |
153 ms |
16468 KB |
Output is correct |
4 |
Correct |
141 ms |
16464 KB |
Output is correct |
5 |
Correct |
148 ms |
16692 KB |
Output is correct |
6 |
Correct |
149 ms |
16724 KB |
Output is correct |
7 |
Correct |
155 ms |
16720 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
0 ms |
348 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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
124 ms |
14508 KB |
Output is correct |
3 |
Correct |
153 ms |
16468 KB |
Output is correct |
4 |
Correct |
141 ms |
16464 KB |
Output is correct |
5 |
Correct |
148 ms |
16692 KB |
Output is correct |
6 |
Correct |
149 ms |
16724 KB |
Output is correct |
7 |
Correct |
155 ms |
16720 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |