Cod sursa(job #2772109)

Utilizator ScobiolaRaduScobiola Radu ScobiolaRadu Data 30 august 2021 19:13:33
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

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

struct tuplu
{
    int x,y,z;
} t;

unordered_map <int,tuplu> jum;

int main()
{
    int N,S,i,j,k,a[101],s,ok=0,ok2=1;
    f>>N>>S;
    for(i=1; i<=N; i++)
        f>>a[i];
    for(i=1; i<=N; i++)
        for(j=i; j<=N; j++)
            for(k=j; k<=N; k++)
            {
                s=a[i]+a[j]+a[k];
                if(S>s)
                {
                    t.x=a[i];
                    t.y=a[j];
                    t.z=a[k];
                    jum[s]=t;
                }
                if((S>s)&&(jum.find(S-s)!=jum.end())&&ok2!=0)
                {
                    g<<a[i]<<" "<<a[j]<<" "<<a[k]<<" ";
                    g<<jum[S-s].x<<" "<<jum[S-s].y<<" "<<jum[S-s].z;
                    ok=1;
                    ok2=0;
                }
            }
    if(ok==0)
        g<<"-1";
    return 0;
}