Cod sursa(job #2896142)

Utilizator DumilexLem-Rau Dumitru Alexandru Dumilex Data 29 aprilie 2022 20:26:18
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct rest
{
    int A, B, C;
};

int n,i,s,a,b,c,auxs,ok;
int v[1000];

unordered_map <int, rest> ump;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    f >> n >> s;
    for(i=1;i<=n;i++)
        f>>v[i];
    for(a=1;a<=n;a++)
        for(b=a;b<=n;b++)
            for(c=a;c<=n;c++)
    ump[v[a]+v[b]+v[c]]={v[a],v[b],v[c]};

    ok=0;
    for(auto i=ump.begin();i != ump.end();i++)
    {
        auxs=s-(*i).first;
        if(ump.find(auxs)!=ump.end())
        {
            ok=1;
            g<<ump[auxs].A<<" "<<ump[auxs].B<<" "<<ump[auxs].C<<" "<<(*i).second.A<<" "<<(*i).second.B<<" "<<(*i).second.C;
        }
        if(ok==1)
            break;
    }
    if(ok==0)
        g<<-1;

    return 0;
}