Cod sursa(job #2887540)

Utilizator RobertuRobert Udrea Robertu Data 9 aprilie 2022 19:33:11
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <fstream>
#include <iostream>
using namespace std;

const int prim = 101;

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

struct Pereche {
    int x = 0, y = 0, z = 0;
}map[102];


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

    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];
                map[(v[i] + v[j] + v[h] % prim)] = 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( map[dif].x != 0 ) {
                    fout << v[i] << " " << v[j] << " " << v[h] << " ";
                    fout << map[dif].x << " " << map[dif].y << " " << map[dif].z;
                    return 0;
                }
            }
        }
    }

    fout << -1;

    return 0;
}