Cod sursa(job #2747257)

Utilizator marabelu131Mara-Luciana Belu marabelu131 Data 28 aprilie 2021 22:54:36
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<iostream>
#include<fstream>
#include<vector>
#include<unordered_map>

using namespace std;

struct solutie{
        int i,j,k;
        };

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

    unordered_map<int, solutie> umap;

    int n,s,nr,ok = 0;
    vector<int> v;

    fin >> n >> s;

    for(int i = 0; i < n; i++)
    {
        fin >> nr;
        v.push_back(nr);
    }

    for(int i = 0; i < n; i++)
        for(int j = i; j < n; j++)
            for(int k = j; k < n; k++)
                umap[v[i]+v[j]+v[k]]={v[i],v[j],v[k]};

    for (auto x : umap)
    {
        if (umap.find(s - x.first) != umap.end())
        {
            fout << umap[s - x.first].i << " " << umap[s - x.first].j <<" " << umap[s - x.first].k <<" ";
            fout << x.second.i << " " << x.second.j << " " << x.second.k;
            ok = 1;
            break;
        }
    }

    if(!ok)
        fout << -1;

    return 0;

}