/**
_ _ __ _ _ _ _ _ _
|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 |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
34 ms |
5544 KB |
Output is correct |
3 |
Correct |
31 ms |
5532 KB |
Output is correct |
4 |
Incorrect |
32 ms |
5456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
34 ms |
5544 KB |
Output is correct |
3 |
Correct |
31 ms |
5532 KB |
Output is correct |
4 |
Incorrect |
32 ms |
5456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
34 ms |
5544 KB |
Output is correct |
3 |
Correct |
31 ms |
5532 KB |
Output is correct |
4 |
Incorrect |
32 ms |
5456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
34 ms |
5544 KB |
Output is correct |
3 |
Correct |
31 ms |
5532 KB |
Output is correct |
4 |
Incorrect |
32 ms |
5456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
34 ms |
5544 KB |
Output is correct |
3 |
Correct |
31 ms |
5532 KB |
Output is correct |
4 |
Incorrect |
32 ms |
5456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |