Submission #751250

#TimeUsernameProblemLanguageResultExecution timeMemory
751250Dan4LifeCandies (JOI18_candies)C++17
100 / 100
176 ms11436 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = (int)2e5+10; priority_queue<array<int,2>> pq; int n, ans, a[N], l[N], r[N], ok[N]; main() { cin >> n; a[0]=a[n+1]=-2e18; for(int i = 1; i <= n; i++) cin >> a[i], pq.push({a[i],i}), l[i]=i-1,r[i]=i+1; for(int j = 0; j < (n+1)/2; j++){ while(ok[pq.top()[1]]) pq.pop(); auto [w,i] = pq.top(); pq.pop(); ok[l[i]]=ok[r[i]]=1; cout<<(ans+=w)<<"\n"; a[i]=a[l[i]]+a[r[i]]-a[i], pq.push({a[i],i}); l[i] = l[l[i]], r[l[i]]=i; r[i] = r[r[i]], l[r[i]]=i; } }

Compilation message (stderr)

candies.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...