Cod sursa(job #2885316)

Utilizator matei123Biciusca Matei matei123 Data 5 aprilie 2022 19:58:20
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("loto.in");
ofstream g("loto.out");
int n, v[105];
long long sum;
int main()
{   unordered_map<int, pair<int, pair<int,int> > > hasxhx;
    f >> n >> sum;
    for(int i = 1; i <= n; i++)
        f >> v[i];
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            for(int k = j; k <= n; k++)
                hasxhx[ v[i] + v[j] + v[k] ] = make_pair(i, make_pair(j, k));
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            for(int k = j; k <= n; k++)
            {   int suma = v[i] + v[j] + v[k];
                if(hasxhx.count(sum - suma)) {
                    g << v[i] << ' ' << v[j] << ' ' << v[k] << ' ' << v[hasxhx[sum - suma].first] << ' ' <<
                     v[hasxhx[sum - suma].second.first] << ' ' << v[hasxhx[sum - suma].second.second];
                    return 0;
                }
            }
    g << -1;
    return 0;
}