#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define ff first
#define ss second
int L[200005], R[200005];
long long A[200005], ans;
set<pii> s;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N; cin >> N;
for (int i = 1; i <= N; ++i) cin >> A[i], s.insert(pii(A[i], i));
iota(L + 1, L + N + 1, 0);
iota(R + 1, R + N + 1, 2);
for (int i = 0; i < (N + 1 >> 1); ++i) {
auto a = --s.end();
int x = a->ss;
ans += A[x];
cout << ans << '\n';
s.erase(a);
A[x] = A[L[x]] + A[R[x]] - A[x];
s.erase(pii(A[L[x]], L[x]));
s.erase(pii(A[R[x]], R[x]));
s.insert(pii(A[x], x));
L[x] = L[L[x]];
R[L[x]] = x;
R[x] = R[R[x]];
L[R[x]] = x;
}
return 0;
}
Compilation message
candies.cpp: In function 'int main()':
candies.cpp:18:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
for (int i = 0; i < (N + 1 >> 1); ++i) {
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |