Cod sursa(job #3131943)

Utilizator LazarDanielGabrielLazar Daniel-Gabriel LazarDanielGabriel Data 21 mai 2023 21:53:10
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");

int main()
{
    int N;
    long long int S, x;
    fin >> N >> S;
    vector<long long int> loto;
    unordered_map<long long int, array<long long int, 3>> solve;
    for (int i = 0; i < N; i++)
    {
        fin >> x;
        loto.push_back(x);
    }
    bool found = false;
    for (int i = 0; i < N && !found; i++)
    {
        for (int j = 0; j < N && !found; j++)
        {
            for (int k = 0; k < N && !found; k++)
            {
                solve[loto[i] + loto[j] + loto[k]] = {loto[i], loto[j], loto[k]};
                long long int minus = S - (loto[i] + loto[j] + loto[k]);
                if (solve.count(minus))
                {
                    fout << loto[i] << " " << loto[j] << " " << loto[k] << " " << solve[minus][0] << " " << solve[minus][1] << " " << solve[minus][2];
                    found = true;
                }
            }
        }
    }
    if (!found)
        fout << -1;
    return 0;
}