Cod sursa(job #2919211)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 16 august 2022 14:53:17
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin ("loto.in");
ofstream fout("loto.out");

const int DIM = 101;
const int TOKEN_DIM = 7;

int n, s, cnt = 0;
int v[DIM], sol[TOKEN_DIM];

int main() {
    fin >> n >> s;
    for (int i = 1; i <= n; i++)
        fin >> v[i];

    sort(v + 1, v + n + 1);

    int index = n, steps = 1;
    while (s > 0 && index > 0 && steps <= 6) {
        if (s >= v[index]) {
            s -= v[index];
            sol[++cnt] = v[index];
            steps++;
        }
        else
            index--;
    }

    if (s > 0)
        fout << -1;
    else {
        for (int i = cnt; i >= 1; i--)
            fout << sol[i] << ' ';
    }

    return 0;
}