Cod sursa(job #3031015)

Utilizator ionicaion ionica Data 18 martie 2023 11:56:20
Problema Loto Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("loto.in");
ofstream fout("loto.out");
int a[101],n,S;
map<int,int>M;
map<int,int>::iterator it1,it2;


int main()
{
    int i,j,k,st,dr,mij,s,u,v,w;
    fin >> n >> S;
    for (i=0; i<n; i++)
        fin >> a[i];

    for (i=0; i<n; i++)
        for (j=i; j<n; j++)
            for (k=j; k<n; k++)
                M[a[i]+a[j]+a[k]]= i*10000+j*100+k+1;

    for (it1=M.begin();it1!=M.end();++it1)
    {
        u=it1->first;
        v=it1->second;
        w=M[S-u];
        if(w!=0)
        {
                int x[6];
                v--;
                x[0] = v% 100;
                x[1] = v/ 100 % 100;
                x[2] = v/ 10000 % 100;

                w--;
                x[3] = w% 100;
                x[4] = w / 100 % 100;
                x[5] = w / 10000 % 100;

                sort(x, x+6);
                for (i=0; i<6; i++)
                    fout << a[x[i]] << ' ';
                return 0;
        }

    }

    fout << -1;

    return 0;
}