제출 #1139422

#제출 시각아이디문제언어결과실행 시간메모리
1139422Dan4LifeCandies (JOI18_candies)C++17
0 / 100
1 ms576 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, t, a[N], l[N], r[N], ok[N]; main() { cin >> n; t=(n+1)/2; 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; while(t--){ 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[i] = r[r[i]]; } }

컴파일 시 표준 에러 (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...