Cod sursa(job #3166358)

Utilizator Paul281881818818181991919191881818Draghici Paul Paul281881818818181991919191881818 Data 8 noiembrie 2023 17:15:37
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>
#include <unordered_map>
#include <algorithm>
std::ifstream fin("loto.in");
std::ofstream fout("loto.out");
int a[101], n, S;
struct T{
    int a, b, c;
};
std::unordered_map<int, T> M;
int main()
{
    std::ios::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);
    fin >> n >> S;
    for(int i = 1; i <= n; i++)
        fin >> a[i];
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            for(int z = j; z <= n; z++)
                M[a[i] + a[j] + a[z]] = {a[i], a[j], a[z]};
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            for(int z = j; z <= n; z++)
            {
                int s = a[i]+a[j]+a[z];
                s = S - s;
                if(M.find(s) != M.end())
                {
                    fout << a[i] << " " << a[j] << " " << a[z] << " "
                    << M[s].a << " " << M[s].b << " " << M[s].c;
                    return 0;
                }
            }
    fout << "-1";
    return 0;

}