Cod sursa(job #2871209)

Utilizator AndreiP15Andrei Enea AndreiP15 Data 13 martie 2022 13:33:02
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <unordered_map>

using namespace std;
const int Nmax = 105;
int n, a[Nmax], S;
struct Triplet {
    int x, y, z;
};
unordered_map<int, Triplet> sume;
int main()
{
    ifstream fin("loto.in");
    ofstream fout("loto.out");
    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 k = j; k <= n; k++) {
                sume[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 complement = S - a[i] - a[j] - a[k];
                if(sume.count(complement) > 0)
                {
                    Triplet t=sume[complement];
                    fout<<a[i]<<" "<<a[j]<<" "<<a[k]<<" "<<t.x<<" "<<t.y<<" "<<t.z<<'\n';
                    return 0;
                }
            }
        }
    }
    fout<<"-1\n";
    return 0;
}