Cod sursa(job #2748127)

Utilizator MihaiBirsanMihai Birsan MihaiBirsan Data 29 aprilie 2021 22:47:21
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <bits/stdc++.h>

using namespace std;

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

#define mod 666013

struct sum {
    int a;
    int b;
    int c;
};

int nr, s, val[101];
unordered_map<int, sum> v;

int main()
{
    fin >> nr >> s;
    for(int i = 0; i < nr; i++)
        fin >> val[i];

    for(int i = 0; i < nr ; i++)
    {
        for(int j = i; j < nr; j++)
        {
            for(int k = j; k < nr; k++)
            {
                v[val[i] + val[j] + val[k]] = {val[i], val[j], val[k]};
            }
        }
    }
    for(auto it:v)
    {
        if(v.find(s-it.first) != v.end())
        {
            fout << v[s-it.first].a << ' ' << it.second.a<< ' ' << v[s-it.first].b << ' ' << it.second.b<<' ' << v[s-it.first].c << ' ' << it.second.c;
            return 0;
        }
    }
    fout << -1;
}