Submission #687817

#TimeUsernameProblemLanguageResultExecution timeMemory
687817wenqiCandies (JOI18_candies)C++17
0 / 100
1 ms340 KiB
// trans rights #include <bits/extc++.h> using namespace std; using ll = long long; using base = complex<double>; #define up(k, N) for (int k = 1; k <= N; k++) #define down(k, N) for (int k = N; k >= 1; k--) #define f0(A) memset(A, 0, sizeof(A)) #define f3(A) memset(A, 0x3f, sizeof(A)) #define all(A) begin(A), end(A) int N; int A[200069]; int L[200069], R[200069]; bool dead[200069]; int main(int argc, const char *argv[]) { ios::sync_with_stdio(false); cin.tie(0); cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; priority_queue<pair<int, int>> pq; for (int i = 1; i <= N; i++) { L[i] = i - 1; R[i] = i + 1; pq.push({A[i], i}); } L[0] = 0; R[0] = 1; L[N + 1] = N; R[N + 1] = N + 1; ll sum = 0; int cnt = 0; while (cnt < (N + 1) / 2) { auto [w, i] = pq.top(); pq.pop(); if (dead[i]) continue; sum += w; cnt++; cout << sum << '\n'; int l = L[i], r = R[i]; A[i] = A[l] + A[r] - A[i]; dead[l] = dead[r] = true; L[i] = L[l], R[i] = R[r]; R[L[i]] = i; L[R[i]] = i; pq.push({A[i], i}); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...