Cod sursa(job #1428146)

Utilizator greenadexIulia Harasim greenadex Data 3 mai 2015 19:07:53
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

struct trio {
    int nr1, nr2, nr3;
};

const int p = 666013;
int N, S;
vector <trio> sums[p];
vector <int> numbers;

int f(int nr) {
    return nr % p;
}

int main() {
    fin >> N >> S;
    for (int i = 1, nr; i <= N; i++) {
        fin >> nr;
        numbers.push_back(nr);
    }
    for (auto x : numbers)
        for (auto y : numbers)
            for (auto z : numbers) {
                int sum = x + y + z;
                if (sum <= S) {
                    trio pack;
                    pack.nr1 = x;
                    pack.nr2 = y;
                    pack.nr3 = z;
                    sums[f(sum)].push_back(pack);
                }
            }

    return 0;

    for (auto x : numbers)
        for (auto y : numbers)
            for (auto z : numbers) {
                int sum = x + y + z;
                if (sums[f(sum)].size() && sums[f(S - sum)].size()) {
                    for (auto it : sums[f(S - sum)])
                        if (it.nr1 + it.nr2 + it.nr3 == S - sum) {
                            fout << x << ' ' << y << ' ' << z << ' '
                                 << it.nr1 << ' ' << it.nr2 << ' ' << it.nr3;
                            return 0;
                        }
                }
            }

    fout << -1;
    return 0;
}