Cod sursa(job #2982050)

Utilizator PHOSSESSEDProsie Radu-Teodor PHOSSESSED Data 19 februarie 2023 14:32:55
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.43 kb
#include<fstream>
#include<unordered_map>
#include<vector>
using namespace std;

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

struct info
{
    int a = -1,b = -1,c = -1;
};

unordered_map<int,info> m;
unordered_map<int,bool> avem;

int main()
{
    int n,s; cin >> n >> s;
    vector<int> v(n); for(auto &it : v) cin >> it;
    for(int i = 0; i < n ; i++)
        {
            for(int j = 0 ; j < n ; j++)
                {
                    for(int k = 0 ; k < n ; k++)
                        {
                            int suma = v[i] + v[j] + v[k];
                            if(avem[suma]) continue;
                            m[suma] = {i,j,k};
                            avem[suma] = 1;
                        }
                }
        }

    for(int i = 0; i < n ; i++)
        {
            for(int j = 0 ; j < n ; j++)
                {
                    for(int k = 0 ; k < n ; k++)
                        {
                            int suma = v[i] + v[j] + v[k];

                            if(s - suma < 3) continue;
                            if(!avem[s - suma]) continue;
                            info one = m[s - suma];
                            cout << v[i] << " " << v[j] << " " << v[k] << " " << v[one.a] << " " << v[one.b] << " " << v[one.c];
                            return 0;


                        }
                }
        }

    cout << -1;
}