Cod sursa(job #1221995)

Utilizator g3ppyStoian Vlad g3ppy Data 21 august 2014 20:34:08
Problema Loto Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <stdio.h>
#include <map>

#define NMAX 101
#define llong long long

using namespace std;

struct three {
    three(int zero, int one, int two) {
        this->zero = zero;
        this->one = one;
        this->two = two;
    }

    llong get_sum() {
        llong sum = 0;
        sum += zero + one + two;
        return sum;
    }

    int zero, one, two;
};

int numbers[NMAX];

map<llong, three> threes;
map<llong, three>::iterator it;
map<llong, three>::iterator sit;



int main() {
    freopen("loto.in", "rt", stdin);
    freopen("loto.out", "wt", stdout);

    llong n, s;
    scanf("%lld %lld\n", &n, &s);


    for (int i = 0; i < n; i++) {
        scanf("%d", &numbers[i]);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                three element(numbers[i], numbers[j], numbers[k]);
                threes.insert(pair<llong, three>(element.get_sum(), element));
            }
        }
    }


    for (it = threes.begin(); it != threes.end(); it++) {
        llong first_sum = it->first;
        llong second_sum = s - first_sum;

        sit = threes.find(second_sum);

        if (sit != threes.end()) {
           printf("%d %d %d %d %d %d\n", it->second.zero, it->second.one, it->second.two, sit->second.zero, sit->second.one, sit->second.two);
           return 0;
        }
    }


    printf("%d\n", -1);

    return 0;
}