Cod sursa(job #2980059)

Utilizator amcbnCiobanu Andrei Mihai amcbn Data 16 februarie 2023 10:23:05
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 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 };
            }
        }
    }
    sort(w.begin(), w.end(), [&](const foo& a, const foo& b) {
        return a.s < b.s;
        });
    int i = 0, j = w.size() - 1;
    while (i < j) {
        if (w[i].s + w[j].s < s) {
            i++;
        }
        else if (w[i].s + w[j].s > s) {
            j--;
        }
        else {
            fout << w[i].a << sp << w[i].b << sp << w[i].c << sp;
            fout << w[j].a << sp << w[j].b << sp << w[j].c;
            return 0;
        }
    }
    fout << -1;
}