Cod sursa(job #2827603)

Utilizator amcbnCiobanu Andrei Mihai amcbn Data 5 ianuarie 2022 22:37:47
Problema Loto Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
/* [A][M][C][B][N] / [K][R][I][P][6][8] */
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
const int mod = 998244353, inf = 0x3f3f3f3f;
const char sp = ' ', nl = '\n';
ifstream fin("loto.in");
ofstream fout("loto.out");

struct tri {
    int s, a, b, c;
    tri(){}
    tri(int _s, int _a, int _b, int _c) {
        s = _s, a = _a, b = _b, c = _c;
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, s;
    fin >> n >> s;
    vector<int> v(n);
    vector<tri> w(n * n * n);
    for (int i = 0; i < n; ++i)
        fin >> v[i];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                int l = i * n * n + j * n + k;
                w[l].a = i, w[l].b = j, w[l].c = k;
                w[l].s = v[i] + v[j] + v[k];
            }
        }
    }
    unordered_map<int, int> mp;
    for (int i = 0; i < w.size(); ++i) {
        if (mp.find(s - w[i].s) != mp.end()) {
            int pr = mp.find(s - w[i].s)->second;
            fout << v[w[i].a] << sp
                 << v[w[i].b] << sp
                 << v[w[i].c] << sp
                 << v[w[pr].a] << sp
                 << v[w[pr].b] << sp
                 << v[w[pr].c];
            return 0;
        }
        else {
            mp[w[i].s] = i;
        }
    }
    fout << -1;
}