Cod sursa(job #2932289)

Utilizator Luka77Anastase Luca George Luka77 Data 2 noiembrie 2022 15:43:46
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <bits/stdc++.h>
using namespace std;

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

struct TRIO
{
    int e1, e2, e3;
};
const int NMAX = 105;
int arr[NMAX], n, s;
unordered_map<int, TRIO>m;

inline void solve()
{
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            for(int k=1;k<=n;++k)
            {
                m[arr[i] + arr[j] + arr[k]] = {arr[i], arr[j], arr[k]};
            }
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            for(int k=1;k<=n;++k)
            {
                if(m.count(s - (arr[i] + arr[j] + arr[k])))
                {
                    TRIO c = m.find(s - (arr[i] + arr[j] + arr[k]))->second;
                    fout << arr[i] << ' ' << arr[j] << ' ' << arr[k] << ' ' << c.e1 << ' ' << c.e2 << ' ' << c.e3;
                    return;
                }
            }
        }
    }
    fout << -1;
}

int main()
{
    fin >> n >> s;
    for(int i=1;i<=n;++i)
        fin >> arr[i];
    solve();
}