Cod sursa(job #3131304)

Utilizator Serban09Baesu Serban Serban09 Data 19 mai 2023 18:58:15
Problema Loto Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<iostream>
#include<fstream>
#include<unordered_map>
#include<string.h>

using namespace std;

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

unordered_map<int, string> m;

int main()
{
    int n, s, a[100];
    f>>n>>s;

    for(int i=0; i<n; i++)
        f>>a[i];

    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            for(int k=0; k<n; k++)
                m[a[i]+a[j]+a[k]] = to_string(a[i]) + " " + to_string(a[j]) + " " + to_string(a[k]) + " ";

    int ok = 0;
    for(auto i : m){
        if(m.find(s-i.first) != m.end()){
            ok = 1;
            g<<m[i.first]<<m[s - i.first]<<endl;
            break;
        }
    }
    if(ok == 0) g<<-1;
    return 0;
}