Cod sursa(job #2747310)

Utilizator EmiHHodoroaba Emanuel EmiH Data 29 aprilie 2021 00:08:03
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <bits/stdc++.h>

using namespace std;

int n, s;
int v[110];
unordered_map <int,pair<int,pair<int,int>>> mapa;

int main(){

    ifstream in("loto.in");
    ofstream out("loto.out");
    in >> n >> s;
    for(int i = 1; i <= n; i++)
       in >> v[i];

    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            for(int k = j; k <= n; k++)
                mapa[v[i] + v[j] + v[k]] = make_pair(i, make_pair(j, k));//create has table
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            for(int k = j; k <= n; k++){
                int total = v[i] + v[j] + v[k];
                if(mapa.count(s - suma)){
                    out << v[i] << " ";
                    out << v[j] << " ";
                    out << v[k] << " ";
                    out << v[mapa[s - total].first] << " ";
                    out << v[mapa[s - total].second.first] << " ";
                    out << v[mapa[s - total].second.second];
                    return 0;
                }
            }
    out << "-1";
    return 0;
}