Cod sursa(job #2981838)

Utilizator cincadavidCinca David Andrei cincadavid Data 18 februarie 2023 20:11:22
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <tuple>

using namespace std;

ifstream cin("loto.in");
ofstream cout("loto.out");

int main()
{
    int n,s;
    cin>>n>>s;
    vector<int>v(n);
    vector<tuple<int,int,int> >half;
    unordered_map<int,tuple<int,int,int> >m;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            for(int k=j;k<n;k++)
            {
                half.push_back(make_tuple(v[i],v[j],v[k]));
                m[v[i]+v[j]+v[k]]=make_tuple(v[i],v[j],v[k]);
            }
        }
    }
    for(int i=0;i<half.size();i++)
    {
        int left=s-(get<0>(half[i])+get<1>(half[i])+get<2>(half[i]));
        if(m.count(left))
        {
            cout<<get<0>(half[i])<<" "<<get<1>(half[i])<<" "<<get<2>(half[i])<<" ";
            cout<<get<0>(m[left])<<" "<<get<1>(m[left])<<" "<<get<2>(m[left]);
            return 0;
        }
    }
    cout<<"-1";

    return 0;
}