Cod sursa(job #3139543)

Utilizator DesqucuDesq Stef Desqucu Data 29 iunie 2023 18:24:42
Problema Loto Scor 65
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
unordered_map<long long, vector<long long>> solve;
int n;
int loto[100];
long long s,rest,sum;
bool gasit = false;
int main()
{
    in>>n>>s;
    for(int i=1;i<=n;i++)
        in >> loto[i];
    for(int i=1;i<=n&&gasit!=true;i++)
    {
        for(int j=1;j<=n && gasit!=true;j++)
        {
            for (int k=1;k<=n&&gasit!=true;k++)
            {
                 sum=loto[i]+loto[j]+loto[k];
                solve[sum]={loto[i], loto[j], loto[k]};
                rest=s-sum;

                if (solve.count(rest))
                {
                    out<<solve[sum][0]<<" "<<solve[sum][1]<<" "<<solve[sum][2]<<" "<<solve[rest][0]<<" "<<solve[rest][1]<<" "<<solve[rest][2];
                    gasit=true;
                }
            }
        }
    }
    if (gasit==0)
        out<<-1;

    return 0;
}