Cod sursa(job #3367599)

Utilizator TimofeiFilipTimofei Filip Emanuel TimofeiFilip Data 8 octombrie 2026 19:13:59
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.54 kb
#include<bits/stdc++.h>
using namespace std;

const int NMAX = 105;

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

int v[NMAX];
typedef long long int ll;

struct Triplet {
    int x, y, z;
};

unordered_map<ll, vector<Triplet>> f;



void read_input(int &n, ll &target_sum) {
    fin >> n >> target_sum;
    for (int i = 1; i <= n; i++) {
        fin >> v[i];
    }
}

void compute_sum_frequency(const int &n) {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                int a = v[i];
                int b = v[j];
                int c = v[k];
                if (f[(ll)(a + b + c)].size() == 0)
                    f[(ll)(a + b + c)].push_back({a, b, c});
            }
        }
    }
}
void compute_result(const int &n, const ll &target_sum) {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                int a = v[i];
                int b = v[j];
                int c = v[k];
                ll dif = target_sum - ((ll)(a + b + c));
                if (!f[dif].empty()) {
                    fout << a << ' ' << b << ' ' << c << ' ' <<  f[dif][0].x << ' '  << f[dif][0].y << ' '  << f[dif][0].z << ' '  << '\n';
                    //int result[6] = {a, b, c, }
                    return;
                }
            }
        }
    }
    fout << "-1\n";
}

int main() {
    int n;
    ll target_sum;
    read_input(n, target_sum);
    compute_sum_frequency(n);
    compute_result(n, target_sum);
    return 0;
}