Cod sursa(job #2736704)

Utilizator Maria23Dutu Maria Maria23 Data 3 aprilie 2021 19:52:19
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <tuple>
#include <utility>
#include <unordered_map>

using namespace std;

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

int verifSuma(const vector<int> &v, const int &n, const int &suma){
    unordered_map<int, tuple<int, int, int>> hash;

    for(int a = 0; a < n; a ++)
        for(int b = 0; b < n; b ++)
            for(int c  = 0; c < n; c ++) {
                hash[v[a] + v[b] + v[c]] = make_tuple(v[a], v[b], v[c]);
            }
    for(int d = 0; d < n; d ++)
        for(int e = 0; e < n; e ++)
            for (int f = 0; f < n; f++)
                if (hash.find(suma - (v[d] + v[e] + v[f])) != hash.end()) {
                    fout << get<0>(hash[suma - (v[d] + v[e] + v[f])]) << " "
                         << get<1>(hash[suma - (v[d] + v[e] + v[f])]) << " "
                         << get<2>(hash[suma - (v[d] + v[e] + v[f])]) << " "
                         << v[d] << " " << v[e] << " " << v[f] << "\n";
                    return 1;
                }
    return 0;
}

int main() {
    vector<int> nr;
    int N, S;
    fin>>N>>S;
    for(int i = 0; i < N; i ++){
        int x;
        fin>>x;
        nr.push_back(x);
    }
    if(!verifSuma(nr, N, S))
        fout<<-1<<"\n";

    fin.close();
    fout.close();
    return 0;
}