Cod sursa(job #2740906)

Utilizator TUdOr73Minciunescu Tudor TUdOr73 Data 14 aprilie 2021 18:37:08
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include <fstream>
#include <tuple>
#include <unordered_map>
using namespace std;

unordered_map<int, tuple<int,int,int>>hash_map;
int main()
{
    int n,s;
    tuple<int,int,int> t;
    ifstream f("loto.in");
    ofstream g("loto.out");
    f >> n >> s;
    int v[n];
    for(int i = 0; i< n; i++)
        f >> v[i];
    for(int i = 0; i < n; i++){
        for(int j = i; j< n; j++){
            for(int p = j; p < n; p++){
                t = make_tuple(v[i],v[j],v[p]);
                hash_map[v[i] + v[j] + v[p]] = t;
            }
        }
    }
    int ok = 0;
    for( auto i:hash_map){
        int target = s - i.first;
        if (hash_map.find(target) != hash_map.end()){ // daca target se afla in hash
            ok = 1;
            t = i.second;
            g << get<0>(t) << " "<< get<1>(t) << " "<< get<2>(t)<<" ";
            t = hash_map[target];
            g << get<0>(t) << " "<< get<1>(t) << " "<< get<2>(t);
            break;
        }
    }
    if (ok == 0)
        g << -1;

    f.close();
    g.close();
    return 0;
}