Cod sursa(job #2801591)

Utilizator Paul281881818818181991919191881818Draghici Paul Paul281881818818181991919191881818 Data 16 noiembrie 2021 17:09:35
Problema Loto Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <unordered_map>
#include<algorithm>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int a[101], n, S;
struct T{
    int a, b, c;
};
unordered_map<int, T> M;
int main()
{
    fin >> n >> S;
    for(int i=1; i<=n; i++) fin >> a[i];
    for(int i=1; i<=n; i++)
        for(int j=i; j<=n; j++)
            for(int z=j; z<=n; z++)
                M[a[i] + a[j] + a[z]] = {a[i], a[j], a[z]};
    for(int i=1; i<=n; i++)
        for(int j=i; j<=n; j++)
            for(int z=j; z<=n; z++)
            {
                int s = a[i]+a[j]+a[z];
                s = S - s;
                if(M.find(s) != M.end())
                {
                    fout << a[i] << " " << a[j] << " " << a[z] << " "
                    << M[s].a << " " << M[s].b << " " << M[s].c;
                    return 0;
                }
            }
    fout << "-1";
    return 0;

}