#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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
472 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
6 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
6 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
7 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
472 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
6 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
348 KB |
Output is correct |
11 |
Correct |
5 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
6 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
5027 ms |
6036 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |