Cod sursa(job #3143748)

Utilizator Dragu_AndiDragu Andrei Dragu_Andi Data 1 august 2023 22:37:56
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
    int n, s;
    fin >> n >> s;
    unordered_map<int,tuple<int,int,int>> f;
    vector<int> v(n);
    for(int i=0; i<n; i++) fin >> v[i];
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            for(int k=0; k<n; k++)
                f.insert(pair<int,tuple<int,int,int>>(v[i]+v[j]+v[k],tuple<int, int, int>(v[i],v[j],v[k])));
    for(unordered_map<int, tuple<int,int,int>>::iterator it = f.begin(); it != f.end(); it++)
    {
        if(f.find(s-(it->first))!=f.end())
        {
            fout << get<0>(it->second) << ' ' << get<1>(it->second) << ' ' << get<2>(it->second) << ' ' << get<0>(f.find(s-(it->first))->second) << ' ' << get<1>(f.find(s-(it->first))->second) << ' ' << get<2>(f.find(s-(it->first))->second);
            return 0;
        }
    }
    fout << -1;
    return 0;
}