This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
long long inf=1e15;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin>>n;
deque<long long>all(n);
for(long long i=0;i<n;i++){
cin>>all[i];
}
long long res=0;
while((long long)all.size()>0){
// cout<<(long long)all.size()<<" salam\n";
long long mx=-inf,w=0;
for(long long i=0;i<(long long)all.size();i++){
if(all[i]>mx){
mx=all[i];
w=i;
}
}
res+=mx;
if(w==0){
all.pop_front();
all.pop_front();
cout<<res<<"\n";
continue;
}
if(w==(long long)all.size()-1){
all.pop_back();
all.pop_back();
cout<<res<<"\n";
continue;
}
long long z=all[w-1]+all[w+1]-all[w];
deque<long long>fake;
for(long long i=0;i<w-1;i++){
fake.push_back(all[i]);
}
fake.push_back(z);
for(long long i=w+2;i<(long long)all.size();i++){
fake.push_back(all[i]);
}
swap(fake,all);
cout<<res<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |