# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
505912 |
2022-01-11T10:03:09 Z |
sidon |
Candies (JOI18_candies) |
C++17 |
|
1 ms |
332 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int Z = 200'002;
const ll oo = 1e18;
/*
Take maximum value (say A[i]) for K = 1, then we have that we either
take A[i] or both A[i-1] and A[i+1]. So add a virtual element weighing
A[i-1] - A[i] + A[i+1] replacing these three elements. Now solve
inductively for (K - 1).
*/
int N, L[Z], R[Z];
ll A[Z], sum;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
// cin >> N;
N = 101;
priority_queue<array<ll, 2>> pq;
for(int i = 1; i <= N; i++) {
// cin >> A[i];
A[i] = 1e9;
L[i] = i - 1;
R[i] = i + 1;
pq.push({A[i], i});
}
A[0] = A[N+1] = oo;
R[N+1] = N+1;
R[0] = 1, L[N+1] = N;
for(int k = 1; k<=(N+1)/2; k++) {
while(A[pq.top()[1]] == oo) pq.pop();
auto [v, i] = pq.top(); pq.pop();
cout << (sum += v) << '\n';
if(A[L[i]] != oo) v -= A[L[i]], A[L[i]] = oo;
if(A[R[i]] != oo) v -= A[R[i]], A[R[i]] = oo;
pq.push({A[i] = -v, i});
R[L[i] = L[L[i]]] = i;
L[R[i] = R[R[i]]] = i;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |