Cod sursa(job #2770753)

Utilizator bestman4111Tiberiu Niculae bestman4111 Data 22 august 2021 23:18:33
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<iostream>
#include<fstream>
#include<unordered_map>
using namespace std;

ifstream cit("loto.in");
ofstream afis("loto.out");

struct triplu{
    int x, y, z;
};

int main()
{
    int N, S, nr[101], suma;
    unordered_map <int, triplu> hash;
    bool ok = false;
    cit>>N>>S;
    for(int i = 0; i < N; i++){
        cit>>nr[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = i; j < N; j++){
            for(int k = j; k < N; k++){
                suma = nr[i] + nr[k] + nr[j];
                if(S > suma){
                    triplu numere;
                    numere.x = nr[i];
                    numere.y = nr[j];
                    numere.z = nr[k];
                    hash[suma] = numere;
                }
                if(hash.find(S - suma) != hash.end()){
                    afis<<nr[i]<<" "<<nr[j]<<" "<<nr[k]<<" "<<hash[S - suma].x<<" "<<hash[S - suma].y<<" "<<hash[S - suma].z;
                    ok = true;
                    i = j = k = N + 1;
                }
            }
        }
    }
    if(ok == false){
        afis<<-1;
    }
    return 0;
}