Cod sursa(job #2746189)

Utilizator Dennis_SoareDennis Soare Dennis_Soare Data 27 aprilie 2021 16:30:24
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");

int n, s;
vector<int> numere;
unordered_map<int, tuple<int, int, int>> suma;

int main()
{
    in >> n >> s;
    for(int i=0; i<n; i++)
    {
        int x;
        in >> x;
        numere.push_back(x);
    }
    for(int i=0; i<n; i++)
    {
        for(int j=i; j<n; j++)
        {
            for(int k=j; k<n; k++)
            {
                suma[numere[i] + numere[j] + numere[k]] = make_tuple(numere[i], numere[j], numere[k]);
            }
        }
    }
    bool ok = false;
    unordered_map<int, tuple<int, int, int>>::iterator i;
    for(i = suma.begin(); i != suma.end(); i++)
    {
        int rest = s - i->first;
        if(suma.find(rest) != suma.end())
        {
            out << get<0>(i->second) <<' '<<get<1>(i->second)<<' '<<get<2>(i->second)<<' ';
            out << get<0>(suma[rest]) <<' '<< get<1>(suma[rest])<<' ' << get<2>(suma[rest]);
            ok = true;
            break;
        }
    }
    if (!ok)
        out<<-1;
    return 0;
}