Cod sursa(job #2893610)

Utilizator adamemi02emanuel adam adamemi02 Data 26 aprilie 2022 13:34:47
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include<unordered_map>

using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");

struct pereche
{int x,y,z;}pereche1;

unordered_map<int,pereche> second;

int main()
{
    int n,s,v[101],s1;
    bool ok=false;
    fin>>n>>s;
    for(int i=1;i<=n;i++)
        fin>>v[i];
    for(int i=1;i<=n&&!ok;i++)
        for(int j=i;j<=n&&!ok;j++)
        for(int t=j;t<=n&&!ok;t++)
    {
        s1=v[i]+v[j]+v[t];
        if(s>s1)
        {
            pereche1.x=v[i];
            pereche1.y=v[j];
            pereche1.z=v[t];
            second[s1]=pereche1;
        }
        if(second.find(s-s1)!=second.end()&&ok==false&&s>s1)
        {
            fout<<v[i]<<" "<<v[j]<<" "<<v[t]<<" "<<second[s-s1].x<<" "<<second[s-s1].y<<" "<<second[s-s1].z;
            ok=true;

        }

    }
    if(ok==false)
        fout<<"-1";
    return 0;
}