Cod sursa(job #2755717)

Utilizator lahayonTester lahayon Data 27 mai 2021 23:43:12
Problema Loto Scor 65
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>
#include <vector>
#include <unordered_map>


using namespace std;

vector<int> values;
int N, S;
    ifstream cin("loto.in");
    ofstream cout("loto.out");

bool checksol(){

    unordered_map<int, vector<int>> hashmap;
    unordered_map<int, vector<int>>::iterator it;


    for(int i = 0; i < N; ++i)
        for(int j = 0; j < N; ++j)
            for(int k = 0; k < N; ++k){

                int curr_sum = values[i] + values[j] + values[k];
                hashmap.insert(pair<int, vector<int>>(curr_sum, {i, j, k}));

                it = hashmap.find(S - curr_sum);
                if(it != hashmap.end()){
                    cout << values[i] << " " << values[j] << " " << values[k] << " " << values[it->second[0]] << " " << values[it->second[1]] << " " << values[it->second[2]];
                    return true;
                } 
            }
    return false;
}

int main()
{ 



    cin >> N >> S;
    values.reserve(N);


    for(int i = 0; i < N; ++i)
        cin >> values[i];

    bool amsol = checksol();
    if(!amsol)
        cout << -1;

  
    

    cin.close();
    cout.close();

  return 0;
}