Comet OJ - Contest #3

Multi evening opened a few games

So this is only a question of a no pipe up

A title race

Water sign title title simulation click on it

AC Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

bool cmp(ll a, ll b){
    return a > b;
}

ll n, k;
ll a[505];
ll b[125000];
ll cnt = 0;
ll ans = 0;

int main(){
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    cin>>n>>k;
    for (int i = 0; i < n; i++) cin>>a[i];
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            b[cnt] = a[i] + a[j];
            cnt++;
        }
    }
    sort(b, b + 124750, cmp);
    for (int i = 0; i < k; i++) ans += b[i];
    cout<<ans<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Misuchii/p/10969369.html