Cod sursa(job #2745445)

Utilizator ptr22222Petru Popescu ptr22222 Data 26 aprilie 2021 15:55:33
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

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

struct triple
{
    int first, second, third;
};

unordered_map <int, triple> loto;
int numere[102];

int main() {
    int n, s;
    in >> n >> s;
    int i, j, k;
    for(i = 1; i <= n; i++)
    {
        in >> numere[i];
    }
    for(i = 1; i <= n; i++)
    {
        for(j = i; j <= n; j++)
        {
            for(k = j; k <= n; k++)
            {
                int sc = numere[i] + numere[j] + numere[k];
                loto[sc].first = numere[i];
                loto[sc].second = numere[j];
                loto[sc].third = numere[k];
                if(loto.find(s-sc) != loto.end())
                {
                    out << numere[i] << " " << numere[j] << " " << numere[k] << " " << loto[s-sc].first << " " << loto[s-sc].second << " " << loto[s-sc].third;
                    return 0;
                }
            }
        }
    }
   out << -1;
    return 0;
}