/**
_ _ __ _ _ _ _ _ _
|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++) {
if (i == N || S[i] != S[i + 1]) {
answer += max(L[i], R[i]) - S[i];
}
}
cout << answer << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
33 ms |
5208 KB |
Output is correct |
3 |
Correct |
32 ms |
5200 KB |
Output is correct |
4 |
Correct |
33 ms |
5092 KB |
Output is correct |
5 |
Correct |
34 ms |
5460 KB |
Output is correct |
6 |
Correct |
40 ms |
5468 KB |
Output is correct |
7 |
Correct |
34 ms |
5540 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
33 ms |
5208 KB |
Output is correct |
3 |
Correct |
32 ms |
5200 KB |
Output is correct |
4 |
Correct |
33 ms |
5092 KB |
Output is correct |
5 |
Correct |
34 ms |
5460 KB |
Output is correct |
6 |
Correct |
40 ms |
5468 KB |
Output is correct |
7 |
Correct |
34 ms |
5540 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
40 ms |
7204 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
33 ms |
5208 KB |
Output is correct |
3 |
Correct |
32 ms |
5200 KB |
Output is correct |
4 |
Correct |
33 ms |
5092 KB |
Output is correct |
5 |
Correct |
34 ms |
5460 KB |
Output is correct |
6 |
Correct |
40 ms |
5468 KB |
Output is correct |
7 |
Correct |
34 ms |
5540 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
40 ms |
7204 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
33 ms |
5208 KB |
Output is correct |
3 |
Correct |
32 ms |
5200 KB |
Output is correct |
4 |
Correct |
33 ms |
5092 KB |
Output is correct |
5 |
Correct |
34 ms |
5460 KB |
Output is correct |
6 |
Correct |
40 ms |
5468 KB |
Output is correct |
7 |
Correct |
34 ms |
5540 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
40 ms |
7204 KB |
Output isn't correct |
11 |
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 |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
33 ms |
5208 KB |
Output is correct |
3 |
Correct |
32 ms |
5200 KB |
Output is correct |
4 |
Correct |
33 ms |
5092 KB |
Output is correct |
5 |
Correct |
34 ms |
5460 KB |
Output is correct |
6 |
Correct |
40 ms |
5468 KB |
Output is correct |
7 |
Correct |
34 ms |
5540 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
40 ms |
7204 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |