Submission #914046

#TimeUsernameProblemLanguageResultExecution timeMemory
914046amirhoseinfar1385Candies (JOI18_candies)C++17
8 / 100
5027 ms6036 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...