#include <bits/stdc++.h>
using namespace std;
vector <int> niz;
int n,iznos;
int main(){
cin>>n;
for(int i=0;i<n;i++){
int broj;
cin>>broj;
niz.push_back(broj);
}
sort(niz.begin(),niz.end());
for(int i=niz.size()-1;i>=0;i-=3){
if(i==0){
iznos+=niz[0];
}else if(i==1){
iznos+=niz[0]+niz[1];
}
else{
iznos+=niz[i];
iznos+=niz[i-1];
}
}
cout<<iznos;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
29 ms |
1328 KB |
Output is correct |
7 |
Correct |
25 ms |
1272 KB |
Output is correct |
8 |
Correct |
25 ms |
1396 KB |
Output is correct |
9 |
Correct |
39 ms |
1396 KB |
Output is correct |
10 |
Correct |
37 ms |
1396 KB |
Output is correct |