Cod sursa(job #2605363)

Utilizator cyg_vladioanBirsan Vlad cyg_vladioan Data 24 aprilie 2020 19:53:33
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int NMAX = 100;
struct loto
{
    int x , y , z;
    loto(int tx = 0 , int ty = 0 , int tz = 0)
    {
        x = tx;
        y = ty;
        z = tz;
    }
};
loto constructor(int tx , int ty , int tz)
{
    loto temp;
    temp.x = tx;
    temp.y = ty;
    temp.z = tz;
    return temp;
}
map <int , loto> m;
int v[NMAX + 5];
int main()
{
    freopen("loto.in" , "r" , stdin);
    freopen("loto.out" , "w" , stdout);
    int n , S , i , j , k , ok , s;
    scanf("%d%d" , &n , &S);
    for(i = 1 ; i <= n ; i ++)
        scanf("%d" , &v[i]);
    sort(v + 1 , v + n + 1);
    if(6 * v[n] < S)
    {
        printf("-1\n");
        return 0;
    }
    ok = 0;
    for(i = 1 ; i <= n && ok == 0; i ++)
        for(j = i ; j <= n && ok == 0; j ++)
            for(k = j ; k <= n && ok == 0; k ++)
            {
                s = v[i] + v[j] + v[k];
                if(m.find(s) == m.end())
                    m.insert({s , loto(v[i] , v[j] , v[k])});
                if(m.find(S - s) != m.end())
                    printf("%d %d %d %d %d %d\n" , m[s].x , m[s].y , m[s].z , m[S - s].x , m[S - s].y , m[S - s].z) , ok = 1;
            }
    if(ok == 0)
        printf("-1\n");
    return 0;
}