Cod sursa(job #3155754)

Utilizator rvfaelbossRafael Stefanescu rvfaelboss Data 9 octombrie 2023 16:54:07
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct triplet
{
    int x, y, z;
};
int n, a[101], s;
unordered_map<int, triplet> sume;
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 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;
                    return 0;
                }
            }
        }
    }
    fout << -1;
    return 0;
}