Rezultati

Up. imeNalogaJezikRezultatČas oddaje
final-solution-2019 Kuponi za pice C 100/100OK 24. apr '19 @ 16:29

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 16/16 2,035 MiB 0,086 s OK
#2 [več] 16/16 1,461 MiB 0,031 s OK
#3 [več] 17/17 1,711 MiB 0,044 s OK
#4 [več] 17/17 1,926 MiB 0,062 s OK
#5 [več] 17/17 2,043 MiB 0,056 s OK
#6 [več] 17/17 2,020 MiB 0,074 s OK

Ocenjevani program (kuponi.c):
#include <stdio.h>
#include <stdlib.h>

static int A[100000];

static int compar(const int *a, const int *b) {
    return *a - *b;
}

int main() {
    int i = 0, n = 0, k = 0;
    long long v = 0;
    scanf("%d %d", &n, &k);
    for (; i < n; i++) {
        int a = 0, b = 0;
        while (scanf("%d", &a) == 1) {
            if (a > b) b = a;
            if (getchar() != ' ') break;
        }
        A[i] = b;
    }
    qsort(A, n, sizeof(A[0]), (int (*)(const void *, const void *))compar);
    for (i = 0; i < k && i < n; i++) v += A[i];
    printf("%lld\n", v);
    return 0;
}