Cod sursa(job #2748116)

Utilizator AndreeaCreitaCreita Andreea AndreeaCreita Data 29 aprilie 2021 22:33:35
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

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

struct numere3
{
    int x,y,z;
};

unordered_map <int, numere3> nrloto;
int v[101],n,s,ok,i,j,k;

int main()
{
    in>>n>>s;
    for(i=1; i<=n; i++)
        in>>v[i];

    for(i=1; i<=n; i++)
        for(j=i; j<=n; j++)
            for(k=j; k<=n; k++)
                nrloto[v[i]+v[j]+v[k]]= {v[i],v[j],v[k]};

    ok=0;
    for(auto i:nrloto)
        if(nrloto.find(s-i.first)!=nrloto.end())
        {
            out<<nrloto[s-i.first].x<<" "<<nrloto[s-i.first].y<<" "<<nrloto[s-i.first].z<< " " <<i.second.x<<" "<<i.second.y <<" "<<i.second.z;
            ok=1;
            break;
        }
    if(ok==0) out<<"-1";
    return 0;
}