Cod sursa(job #2457660)

Utilizator cyber_ghSoltan Gheorghe cyber_gh Data 18 septembrie 2019 14:13:43
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#pragma optmize GCC("O3")
#include <iostream>
#include <fstream>
#include <map>
#include <unordered_map>

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

int N, M;
int arr[110];

struct sol {
    int x1, x2, x3;
};


unordered_map<int, sol> sum;

int main() {
    sum.reserve(1000010);
    fin >> N >> M;

    for (int i = 1; i <= N;i++) fin >> arr[i];
    for (int i = 1; i <= N;i++)
    for (int j = i; j <= N;j++)
    for (int k = j; k <= N;k++) {
        sum[ arr[i] + arr[j] + arr[k] ] = {arr[i], arr[j], arr[k]};
    }

    for (auto it: sum) {
        if (sum.count(M - it.first)) {
            fout << it.second.x1 << " " << " " << it.second.x2 << " " << it.second.x3 << " ";
            sol sol2 = sum[M-it.first];
            fout << sol2.x1 << " " << sol2.x2 << " " <<sol2.x3;
            return 0;
        }
    }

    fout << "-1";
    return 0;
}