Cod sursa(job #3311601)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 23 septembrie 2025 15:38:54
Problema Loto Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

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

const int NMAX = 100;

int n, s;
int a[NMAX + 1];
map<int, tuple<int, int, int>> mp;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    fin >> n >> s;
    for(int i = 1; i <= n; i++) {
        fin >> a[i];
    }

    for(int i = n; i >= 1; i--) {
        for(int j = i; j >= 1; j--) {
            for(int k = j; k >= 1; k--) {
                int sum_need = s - a[i] - a[j] - a[k];
                if(mp.find(sum_need) != mp.end()) {
                    auto [x, y, z] = mp[sum_need];
                    fout << a[i] << ' ' << a[j] << ' ' << a[k] << ' ' << x << ' ' << y << ' ' << z << '\n';
                    return 0;
                }
            }
        }
        for(int j = i; j <= n; j++) {
            for(int k = j; k <= n; k++) {
                int sum = a[i] + a[j] + a[k];
                if(mp.find(sum) == mp.end()) {
                    mp[sum] = {a[i], a[j], a[k]};
                }
            }
        }
    }
    fout << -1 << '\n';
    return 0;
}