Cod sursa(job #2895256)

Utilizator biancar28Radulescu Alexia-Bianca biancar28 Data 28 aprilie 2022 20:51:42
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <iostream>
#include <unordered_map>
#include <tuple>
#include <fstream>
#include <iterator>

using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");

int main() {

    int n,s,i,suma,dif,j,z,ok=0,v[101];
    f>>n>>s;
    unordered_map<int, tuple<int,int,int>>M;

    for(i=0;i<n;i++)
    {
        f>>v[i];
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            for(z=0;z<n;z++)
            {
                suma = v[i]+v[j]+v[z];
                if(suma<=s)
                {
                    M[suma]=make_tuple(v[i],v[j],v[z]);
                }
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            for(z=0;z<n;z++)
            {
                dif = s-v[i]-v[j]-v[z];
                if(M.find(dif) != M.end()){
                    g<<get<0>(M[dif])<<" "<<get<1>(M[dif])<<" "<<get<2>(M[dif])<<" ";
                    g<<v[i]<<" "<<v[j]<<" "<<v[z]<<" ";
                    ok=1;
                    break;
                }
            }
            if(ok==1)
                break;
        }
        if(ok==1)
            break;
    }
    if(ok==0){
        g<<-1;
    }

    g.close();
    f.close();

    return 0;
}