#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
const int NS = (int)2e5 + 4;
int n, m, q;
int a[NS], srt[NS], chk[NS];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> q;
int ans = 0;
for(int i = 1; i <= n; ++i){
cin >> a[i];
if(i > 1){
ans += min(a[i - 1], a[i]);
}
}
iota(srt, srt + NS, 0);
sort(srt + 1, srt + n + 1, [&](int x, int y){return a[x] > a[y];});
int gr = 1;
chk[0] = chk[n + 1] = 1;
for(int i = 1; i <= n; ++i){
int now = srt[i];
chk[now] = 1;
if(!chk[now - 1] && !chk[now + 1]) ++gr;
if(chk[now - 1] && chk[now + 1]) --gr;
if(a[srt[i]] != a[srt[i + 1]]){
// cout << i << ' ' << now << ' ' << ans << ' ' << gr << endl;
ans += gr;
}
}
assert(gr == 0);
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
15 ms |
5000 KB |
Output is correct |
3 |
Correct |
16 ms |
4920 KB |
Output is correct |
4 |
Correct |
18 ms |
4892 KB |
Output is correct |
5 |
Correct |
19 ms |
4948 KB |
Output is correct |
6 |
Correct |
18 ms |
4996 KB |
Output is correct |
7 |
Correct |
17 ms |
4948 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
15 ms |
5000 KB |
Output is correct |
3 |
Correct |
16 ms |
4920 KB |
Output is correct |
4 |
Correct |
18 ms |
4892 KB |
Output is correct |
5 |
Correct |
19 ms |
4948 KB |
Output is correct |
6 |
Correct |
18 ms |
4996 KB |
Output is correct |
7 |
Correct |
17 ms |
4948 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1820 KB |
Output is correct |
10 |
Incorrect |
41 ms |
4880 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
15 ms |
5000 KB |
Output is correct |
3 |
Correct |
16 ms |
4920 KB |
Output is correct |
4 |
Correct |
18 ms |
4892 KB |
Output is correct |
5 |
Correct |
19 ms |
4948 KB |
Output is correct |
6 |
Correct |
18 ms |
4996 KB |
Output is correct |
7 |
Correct |
17 ms |
4948 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1820 KB |
Output is correct |
10 |
Incorrect |
41 ms |
4880 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
15 ms |
5000 KB |
Output is correct |
3 |
Correct |
16 ms |
4920 KB |
Output is correct |
4 |
Correct |
18 ms |
4892 KB |
Output is correct |
5 |
Correct |
19 ms |
4948 KB |
Output is correct |
6 |
Correct |
18 ms |
4996 KB |
Output is correct |
7 |
Correct |
17 ms |
4948 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1820 KB |
Output is correct |
10 |
Incorrect |
41 ms |
4880 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1876 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1876 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
15 ms |
5000 KB |
Output is correct |
3 |
Correct |
16 ms |
4920 KB |
Output is correct |
4 |
Correct |
18 ms |
4892 KB |
Output is correct |
5 |
Correct |
19 ms |
4948 KB |
Output is correct |
6 |
Correct |
18 ms |
4996 KB |
Output is correct |
7 |
Correct |
17 ms |
4948 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1820 KB |
Output is correct |
10 |
Incorrect |
41 ms |
4880 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |