Cod sursa(job #2892915)

Utilizator DariaClemClem Daria DariaClem Data 23 aprilie 2022 23:12:45
Problema Loto Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <bits/stdc++.h>

using namespace std;

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

unordered_map<int, tuple<int, int, int>> loto;
int nrNumere, suma, numere[100];

int main() {
    int index1, index2, index3;
    unordered_map<int, tuple<int, int, int>>::iterator complement;
    fin >> nrNumere >> suma;
    for (index1 = 0; index1 < nrNumere; index1 += 1) {
        fin >> numere[index1];
    }
    for (index1 = 0; index1 < nrNumere; index1 += 1) {
        for (index2 = index1; index2 < nrNumere; index2 += 1) {
            for (index3 = index2; index3 < nrNumere; index3 += 1) {
                complement = loto.find(suma - numere[index1] - numere[index2] - numere[index3]);
                if (complement != loto.end()) {
                    fout << numere[index1] << " " << numere[index2] << " " << numere[index3] << " "
                         << get<0>(complement->second) << " " << get<1>(complement->second) << " "
                         << get<2>(complement->second);
                    return 0;
                }
                loto[numere[index1] + numere[index2] + numere[index3]] = make_tuple(numere[index1], numere[index2],
                                                                                    numere[index3]);
            }
        }
    }
    fout << -1;
    return 0;
}