#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> val(n);
for (int i = 0; i < n; ++i)
{
cin>>val[i];
}
vector<vector<int>> arr(n);
for (int i = 0; i < m; i++){
int u,v;cin>>u>>v;
arr[u-1].push_back(v-1);
arr[v-1].push_back(u-1);
}
vector<int> dp1(n);
vector<int> dp2(n);
int crmax = 0;
int crans = 0;
int ans = INF;
for (int i = 1; i < n; ++i)
{
if (crmax>=val[i]) crans++;
else crans+=val[i]-crmax;
dp1[i]=crans;
crmax=max(crmax,val[i]);
}
ans=crans+crmax;
crmax=0;
crans=0;
for (int i = n-2; i >= 0; --i){
if (crmax>=val[i]) crans++;
else crans+=val[i]-crmax;
dp2[i]=crans;
crmax=max(crmax,val[i]);
}
ans=min(ans,crans+crmax);
for (int i = 1; i < n-1; ++i)
{
ans=min(ans,dp1[i]+dp2[i]);
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
123 ms |
16048 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 |
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 |
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 |
123 ms |
16048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |