Cod sursa(job #2412337)

Utilizator alex2kamebossPuscasu Alexandru alex2kameboss Data 22 aprilie 2019 09:33:11
Problema Loto Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <tuple>

#define N 105

using namespace std;

int a[N], n, s;
set<int> ps;
map<int,tuple<int,int,int>> val;

int main()
{
    freopen("loto.in","r",stdin);
    freopen("loto.out","w",stdout);

    scanf("%d%d", &n, &s);
    for(int i = 0; i < n; ++i)
        scanf("%d", &a[i]);

    for(int i = 0; i < n; ++i)
        for(int j = i; j < n; ++j)
            for(int k = j; k < n; ++k){
                int sum = a[i]+a[j]+a[k];
                ps.insert(sum);
                val[sum] = {i,j,k};
            }

    for(int i : ps)
        if(ps.find(s-i)!=ps.end()){
            int x,y,z;
            tie(x,y,z) = val[i];
            printf("%d %d %d ", a[x], a[y], a[z]);
            tie(x,y,z) = val[s-i];
            printf("%d %d %d ", a[x], a[y], a[z]);
            return 0;
        }

    cout<<-1;

    return 0;
}