#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int mxN = (int)2e3+10;
const int LINF = (int)2e18;
int n, a[mxN], l[mxN], r[mxN], ok[mxN];
priority_queue<array<int,2>> pq;
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n; int ans = 0;
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;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |