Cod sursa(job #2895813)

Utilizator Alexandru_PotangaPotanga Alexandru Alin Alexandru_Potanga Data 29 aprilie 2022 14:59:16
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct jumate
{
    int a, b, c;
};
unordered_map <int, jumate> sum;
int main()
{
    int n, suma, i, q, w , e, temp;
    f >> n >> suma;
    int v[n+1];
    for(i = 0; i < n; i++)
    {
        f >> v[i];
    }

    for(q = 0; q < n; q++)
        for(w = q; w < n; w++)
            for(e = w; e < n; e++)
            {
                sum.insert(pair<int, jumate>(v[q] + v[w] + v[e], {v[q], v[w], v[e]}));
            }

    bool ok = false;

    for(auto it = sum.begin(); it != sum.end() && ok == false; it++)
    {
        temp = suma - it->second.a - it->second.b - it->second.c;
        if(sum.find(temp) != sum.end())
        {
            ok = true;
            g << sum[temp].a << " " << sum[temp].b << " " << sum[temp].c << " " << it->second.a << " " << it->second.b << " " << it->second.c;
        }
    }

    if(ok == false)
        g << -1;

    return 0;
}