#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=500010, inf=2e9;
list<ll> X;
int n, A[MX];
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>A[i];
for(int i=1; i<=n; i++) X.push_back(A[i]);
ll ans=0;
for(int j=1; j<=(n+1)/2; j++){
auto it=max_element(X.begin(), X.end());
ans+=*it;
cout<<ans<<'\n';
*it=-*it;
if(it!=X.begin()) *it+=*prev(it), X.erase(prev(it));
if(next(it)!=X.end()) *it+=*next(it), X.erase(next(it));
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |