# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
861126 | 2023-10-15T11:36:49 Z | eitanelb | Candies (JOI18_candies) | C++14 | 2 ms | 348 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define x first #define y second #define pi pair<int,int> int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector<ll> v(n); for(ll &i : v) cin>>i; int k = (n+1)/2; priority_queue<pi> pq; int l[n],r[n]; for(int i=0;i<n;i++){ pq.push({v[i],i}); l[i]=i-1;r[i]=i+1; } vector<bool> vis(n,0); ll res=0; for(int i=0; i< (n+1)/2;i++){ while(vis[pq.top().y]){ pq.pop(); } pi p = pq.top(); pq.pop(); res += p.x; cout<<res<<endl; int cur = p.y; if(r[cur]==n){ vis[cur]=1; if(l[cur]!=-1)vis[l[cur]]=1; if(l[l[cur]] > -1) r[l[l[cur]]]=n; } else if(l[cur]==-1){ vis[cur]=1; if(r[cur]!=n)vis[r[cur]]=1; if(r[r[cur]] < n) l[r[r[cur]]]=-1; } else{ v[cur] = v[r[cur]]+v[l[cur]] - v[cur]; vis[r[cur]]=1; r[cur] = r[r[cur]]; if(r[cur] != n) l[r[cur]]=cur; vis[l[cur]]=1; l[cur] = l[l[cur]]; if(l[cur] != -1) r[l[cur]]=cur; pq.push({v[cur],cur}); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |