This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
const int M_MAX = 400000;
const int Q_MAX = 200000;
int N, M, Q;
int S[N_MAX + 2];
int L[N_MAX + 2], R[N_MAX + 2];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> Q;
assert(M == N - 1 && Q == 0);
for (int i = 1; i <= N; i++) {
cin >> S[i];
}
for (int i = 1; i <= M; i++) {
int u, v;
cin >> u >> v;
assert(u == i && v == i + 1);
}
for (int i = 1; i <= N; i++) {
if (i > 1 && S[i] >= S[i - 1]) {
L[i] = S[i];
} else {
L[i] = L[i - 1];
}
}
for (int i = N; i >= 1; i--) {
if (i < N && S[i] >= S[i + 1]) {
R[i] = S[i];
} else {
R[i] = R[i + 1];
}
}
ll answer = 0;
for (int i = 1; i + 1 <= N; i++) {
answer += min(S[i], S[i + 1]);
}
for (int i = 1; i <= N; i++) {
answer += max(L[i], R[i]) - S[i];
}
cout << answer << "\n";
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |