#include <fstream>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<int>c(n);
for(int i=0;i<n;i++){
cin>>c[i];
}
sort(c.rbegin(),c.rend());
int r=0,y;
if(n%3==0){
y=n;
}
else if(n%3==1){
y=n-1;
r=c[n-1];
}
else{
y=n-2;
r=c[n-1]+c[n-2];
}
for(int i=0;i<y/3;i++){
r+=c[i*3]+c[i*3+1];
}
cout<<r;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
14 ms |
748 KB |
Output is correct |
7 |
Correct |
10 ms |
748 KB |
Output is correct |
8 |
Correct |
10 ms |
748 KB |
Output is correct |
9 |
Correct |
18 ms |
748 KB |
Output is correct |
10 |
Correct |
18 ms |
748 KB |
Output is correct |