Cod sursa(job #2746947)

Utilizator oporanu.alexAlex Oporanu oporanu.alex Data 28 aprilie 2021 18:22:17
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <bits/stdc++.h>

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

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

int main()
{
    f >> n >> s;
    for(int i=0; i<n; i++)
    {
        int x;
        f >> 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())
        {
            g << get<0>(i->second) <<' '<<get<1>(i->second)<<' '<<get<2>(i->second)<<' ';
            g << get<0>(suma[rest]) <<' '<< get<1>(suma[rest])<<' ' << get<2>(suma[rest]);
            ok = true;
            break;
        }
    }
    if (!ok)
        g<<-1;
    return 0;
}