Cod sursa(job #2980176)

Utilizator amcbnCiobanu Andrei Mihai amcbn Data 16 februarie 2023 11:22:26
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
/// [A][M][C][B][N] ///
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const char sp = ' ', nl = '\n';
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");

struct foo {
    int s, a, b, c;
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, s;
    fin >> n >> s;
    vector<int> v(n);
    for (auto& x : v) {
        fin >> x;
    }
    vector<foo> w(n * n * n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                w[i * n * n + j * n + k] = { v[i] + v[j] + v[k], i + 1, j + 1, k + 1 };
            }
        }
    }
    map<int, int> mp;
    for (int i = 0; i < w.size(); ++i) {
        if (mp.count(s - w[i].s)) {
            int j = mp[s - w[i].s];
            fout << w[i].a << sp;
            fout << w[i].b << sp;
            fout << w[i].c << sp;
            fout << w[j].a << sp;
            fout << w[j].b << sp;
            fout << w[j].c;
            return 0;
        }
        mp[w[i].s] = i;
    }
    fout << -1;
}