Cod sursa(job #2892469)

Utilizator AndreiBerbecaruBerbecaru-Iovan Andrei AndreiBerbecaru Data 22 aprilie 2022 11:57:42
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<fstream>
#include<unordered_map>
using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

struct triplet{
    int a, b, c;
};

int n, m, suma, ok, s, v[101];
unordered_map<int, triplet> loto;


int main(){
    fin>>n>>s;
    for(int i=1; i<=n; i++)
        fin>>v[i];

    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j++){
            for(int k=j; k<=n; k++){
                loto[v[i]+v[j]+v[k]]={v[i], v[j], v[k]};
            }
        }
    }

    unordered_map<int, triplet>::iterator it;

    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j++){
            for(int k=j; k<=n; k++){
                suma=s-v[i]-v[j]-v[k];
                if(loto.count(suma)!=0){
                    it=loto.find(suma);
                    fout<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<it->second.a<<" "<<it->second.b<<" "<<it->second.c;
                    return 0;
                }
            }
        }
    }

    fout<<-1;

}