Rezultati

Up. imeNalogaJezikRezultatČas oddaje
algebros-2019 Kuponi za pice C++ 100/100OK 24. apr '19 @ 18:32

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 16/16 4,012 MiB 0,043 s OK
#2 [več] 16/16 3,781 MiB 0,000 s OK
#3 [več] 17/17 3,469 MiB 0,012 s OK
#4 [več] 17/17 4,012 MiB 0,049 s OK
#5 [več] 17/17 4,039 MiB 0,061 s OK
#6 [več] 17/17 4,008 MiB 0,049 s OK

Ocenjevani program (Kuponi.cpp):
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;
vector<long long> v;
char s[1001000];

int main()
{
    int a, b, e, c;
    long long r = 0, x, m;
    char bla;
    scanf("%d %d",&a,&b);
    bla = getchar();

    for(int i = 0; i < a; i++)
    {
        m = 0;
        scanf("%[^\n]",s);
        bla = getchar();
        e = strlen(s);
        c = 0;
        
        while(c < e)
        {
            x = 0;

            while(c < e && s[c] != ' ')
            {
                x = x * 10;
                x += s[c] - '0';
                c++;
            }

            m = max(x,m);
            c++;
        }

        v.push_back(m);
    }

    sort(v.begin(),v.end());

    for(int i = 0; i < b; i++)
        r += v[i];

    printf("%lld\n",r);
}