Cod sursa(job #3252253)

Utilizator Gabriel_DaescuDaescu Gabriel Florin Gabriel_Daescu Data 28 octombrie 2024 21:58:30
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");
struct Valori {
    int a, b, c;
};
int n, s, i, j, k, a[102];
unordered_map<int, Valori> fr;

int main() {
    fin >> n >> s;
    for(i = 1; i <= n; i++) fin >> a[i];
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= n; j++) {
            for(k = 1; k <= n; k++) fr[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
        }
    }
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= n; j++) {
            for(k = 1; k <= n; k++) {
                int sum = a[i] + a[j] + a[k];
                if(sum <= s) {
                    auto it = fr.find(s - sum);
                    if(it != fr.end()) {
                        fout << a[i] << " " << a[j] << " " << a[k] << " ";
                        Valori v = it->second;

                        fout << v.a << " " << v.b << " " << v.c;

                        return 0;
                    }
                }
            }
        }
    }
    fout << "-1";

	return 0;
}