Cod sursa(job #2823695)

Utilizator antonio_sefu_tauLaslau Antonio antonio_sefu_tau Data 29 decembrie 2021 14:21:13
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <bits/stdc++.h>

using namespace std;

const int dim = 105;
int n, a[dim], s;

struct triplet
{
    int x;
    int y;
    int z;
};

unordered_map<int, triplet> sum;

int main()
{
    ifstream f("loto.in");
    ofstream g("loto.out");
    f >> n >> s;
    for(int i = 1; i <= n; i++)
        f >> a[i];
    for(int i = 1; i <= n; i++)
    {
        for(int j = i; j <= n; j++)
        {
            for(int k = j; k <= n; k++)
            {
               sum[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = i; j <= n; j++)
        {
            for(int k = j; k <= n; k++)
            {
               int c = s - a[i] - a[j] - a[k];
               if(sum.count(c))
               {
                   triplet t = sum[c];
                   g << a[i] << ' ' << a[j] << ' ' << a[k] << ' ' << t.x << ' ' << t.y << ' ' << t.z;
                   return 0;
               }
            }
        }
    }
    g << -1;
    return 0;
}