// soab
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl '\n'
void io() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
const int maxn = 2 * 1e5 + 1;
int n, m, a[maxn];
vector<int> g[2 * maxn];
signed main() {
io();
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 0; i < m; i++) {
int x, y; cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
int ans = 0, maxn = 0, l, r;
for(int i = 1; i <= n; i++) {
if(maxn < a[i]) {
maxn = a[i];
l = i;
}
if(maxn <= a[i]) r = i;
}
for(int i = 2; i <= l; i++) {
if(a[i - 1] > a[i]) a[i] = a[i - 1] + 1;
}
for(int i = l; i <= r; i++) {
a[i] = maxn;
}
for(int i = n - 1; i > r; i--) {
if(a[i + 1] > a[i]) a[i] = a[i + 1] + 1;
}
for(int i = 2; i <= n; i++) {
if(a[i] == a[i - 1]) ans++;
else ans += abs(a[i] - a[i - 1]);
}
cout << ans;
return 0;
}
# | 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... |