← Back to List

11508번: 2+1 세일 ↗

Solutions

C++14
343 B | 343 chars
#include <iostream>
#include <algorithm>
using namespace std;
int N,ans;
int ar[110000];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N;
    for(int x=0; x<N; x++) cin >> ar[x];    
    sort(ar,ar+N,greater <int> ());
    for(int x=0; x<N; x+=3) {
        ans += ar[x] + ar[x+1];
    }
    cout<<ans;
}