Cod sursa(job #2887534)

Utilizator RobertuRobert Udrea Robertu Data 9 aprilie 2022 19:27:57
Problema Loto Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <bits/stdc++.h>
using namespace std;

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

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

map<int, Pereche> umap;

int main() {
    int v[303], n, S, nr, k = 0;
    fin >> n >> S;
    for(int i = 0; i < n; i++) {
        fin >> nr;
        v[k++] = nr;
        v[k++] = nr;
        v[k++] = nr;
    }

    Pereche a;
    for(int i = 0; i < k - 2; i++) {
        a.x = v[i];
        for(int j = i + 1; j < k - 1; j++) {
            a.y = v[j];
            for(int h = j + 1; h < k; h++) {
                a.z = v[h];
                umap[v[i] + v[j] + v[h]] = a;
            }
        }
    }

    int dif;
    for(int i = 0; i < k - 2; i++) {
        for(int j = i + 1; j < k - 1; j++) {
            for(int h = j + 1; h < k; h++) {
                dif = S - v[i] - v[j] - v[h];
                if( umap[dif].x != 0 ) {
                    fout << v[i] << " " << v[j] << " " << v[h] << " ";
                    fout << umap[dif].x << " " << umap[dif].y << " " << umap[dif].z;
                    return 0;
                }
            }
        }
    }

    fout << -1;

    return 0;
}