#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using ld = long double;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
vector<int> S;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n, m, q;
cin >> n >> m >> q;
S.resize(n);
for(auto &x : S) cin >> x;
ll sum = 0;
for(int i = 0; i < n - 1; i++)
sum += (S[i] == S[i + 1]) * S[i];
S.erase(unique(all(S)), end(S));
n = sz(S);
vector<int> mx;
if(sz(S) > 1 && S[0] > S[1])
mx.emplace_back(S[0]);
for(int i = 1; i < n - 1; i++) {
if(S[i] > S[i - 1] && S[i] > S[i + 1])
mx.emplace_back(S[i]);
if(S[i] < S[i - 1] && S[i] < S[i + 1])
mx.emplace_back(S[i]);
}
if(sz(S) > 1 && rbegin(S)[0] > rbegin(S)[1])
mx.emplace_back(S.back());
for(int i = 0; i < n - 1; i++)
sum += max(S[i], S[i + 1]);
for(int i = 0; i + 2 < sz(mx); i += 2)
sum -= min(mx[i], mx[i + 2]) - mx[i + 1];
cout << sum << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
1628 KB |
Output is correct |
3 |
Correct |
10 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
2528 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
10 ms |
2272 KB |
Output is correct |
7 |
Correct |
11 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
1628 KB |
Output is correct |
3 |
Correct |
10 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
2528 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
10 ms |
2272 KB |
Output is correct |
7 |
Correct |
11 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
18 ms |
4536 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
1628 KB |
Output is correct |
3 |
Correct |
10 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
2528 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
10 ms |
2272 KB |
Output is correct |
7 |
Correct |
11 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
18 ms |
4536 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
1628 KB |
Output is correct |
3 |
Correct |
10 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
2528 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
10 ms |
2272 KB |
Output is correct |
7 |
Correct |
11 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
18 ms |
4536 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 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 |
Correct |
12 ms |
1628 KB |
Output is correct |
3 |
Correct |
10 ms |
1628 KB |
Output is correct |
4 |
Correct |
10 ms |
2528 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
10 ms |
2272 KB |
Output is correct |
7 |
Correct |
11 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
18 ms |
4536 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |