Cod sursa(job #2755704)

Utilizator lahayonTester lahayon Data 27 mai 2021 23:30:11
Problema Loto Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <unordered_map>


using namespace std;


int main()
{ 

    ifstream cin("loto.in");
    ofstream cout("loto.out");

    int N, S;
    cin >> N >> S;
    vector<int> values(N);

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

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

    bool amsol = false;

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

                int curr_sum = values[i] + values[j] + values[k];

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

                hashmap.insert(pair<int, vector<int>>(curr_sum, {i, j, k}));
            }
    
    if(!amsol)
        cout << -1;

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

  return 0;
}