Cod sursa(job #3252251)

Utilizator Gabriel_DaescuDaescu Gabriel Florin Gabriel_Daescu Data 28 octombrie 2024 21:57:19
Problema Loto Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <bits/stdc++.h>
#define NMAX 102
using namespace std;
ifstream  fin("loto.in");
ofstream fout("loto.out");
int N,s,S,v[NMAX];

struct triplet
{
    int a,b,c;
};
unordered_map <int,triplet> M;

void citire()
{
    fin>>N>>S;

    for(int i=1; i<=N; i++)
    {
        fin>>v[i];
    }
}

int main()
{
    citire();

    for(int i=1; i<=N; i++)
    {
        for(int j=1; j<=N; j++)
        {
            for(int k=1; j<=N; j++)
            {
                if(v[i]+v[j]+v[k]<=S)
                {
                    M[v[i]+v[j]+v[k]]={v[i],v[j],v[k]};
                }
            }
        }
    }

    s=0;
    for(int i=1; i<=N; i++)
    {
        for(int j=1; j<=N; j++)
        {
            for(int k=1; j<=N; j++)
            {
                s=v[i]+v[j]+v[k];
                if(s<=S)
                {
                    auto it=M.find(S-s);
                    if(it!=M.end())
                    {
                        fout<< v[i] << " " << v[j] << " " << v[k] << " ";
                        triplet x=it->second;
                        fout<< x.a << " " << x.b << " " << x.c;
                        return 0;
                    }
                }
            }
        }
    }

    fout<< -1;

    return 0;
}