Cod sursa(job #2976970)

Utilizator PatruMihaiPatru Mihai PatruMihai Data 10 februarie 2023 14:58:19
Problema Loto Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>

using namespace std;

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

struct loto
{
    int a, b, c;
};

const int NMAX = 107;

unordered_map<int, loto> m;
vector<loto> sum;
int v[NMAX];

int main()
{
    int n, s;
    fin >> n >> s;

    for (int i = 1; i <= n; ++i)
        fin >> v[i];

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            for (int k = 1; k <= n; ++k)
            {
                sum.push_back({v[i], v[j], v[k]});
                int suma = v[i] + v[j] + v[k];
                m[suma] = {v[i], v[j], v[k]};
            }

    for (auto [a, b, c] : sum)
    {
        int ramas = s - a - b - c;
        if (m.find(ramas) != m.end())
        {
            fout << a << " " << b << " " << c << " " << m[ramas].a << " " << m[ramas].b << " " << m[ramas].c;
            return 0;
        }
    }

    fout << "-1";
    return 0;
}