#include "bits/stdc++.h"
using namespace std;
#define intt long long
#define fi first
#define se second
const intt mxN = 1e5 + 5;
const intt LG = 20;
const intt inf = 1e18;
intt n;
vector<intt> a(mxN);
void _() {
cin >> n;
intt s = 0;
for(intt i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
if(n <= 2) {
cout << s << endl;
return;
}
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
intt c = 0;
for(intt i = 2; i < n; i += 3) {
c += a[i];
if(i + 3 > n - 1) {
break;
}
}
cout << s - c << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
intt t = 1, buu = 1;
// cin >> t;
while(t--){
// cout << "Case #" << buu++ << ": ";
_();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |