Cod sursa(job #1680186)

Utilizator razvandRazvan Dumitru razvand Data 8 aprilie 2016 16:05:46
Problema Loto Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 67777

using namespace std;

struct rez {
    int a;
    int b;
    int c;
    int Su;
    bool E;
};

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

int v[102];
vector<rez> sum[MOD];
rez temp;
vector<rez>::iterator it;

int main() {

    int n,S;
    in >> n >> S;

    for(int i = 1; i <= n; i++)
        in >> v[i];

    for(int a = 1; a <= n; a++) {
        for(int b = 1; b <= n; b++) {
            for(int c = 1; c <= n; c++) {
                temp.a = a;
                temp.b = b;
                temp.c = c;
                temp.Su = v[a]+v[b]+v[c];
                temp.E = true;
                sum[(v[a]+v[b]+v[c])%MOD].push_back(temp);
            }
        }
    }

    for(int d = 1; d <= n; d++) {
        for(int e = 1; e <= n; e++) {
            for(int f = 1; f <= n; f++) {
                if(sum[(S-v[d]-v[e]-v[f])%MOD].size() != 0) {
                    for(it = sum[(S-v[d]-v[e]-v[f])%MOD].begin(); it != sum[(S-v[d]-v[e]-v[f])%MOD].end(); it++) {
                        if(S-v[d]-v[e]-v[f] == it->Su) {
                            temp = *it;
                            out << v[d] << " " << v[e] << " " << v[f] << " " << v[temp.c] << " " << v[temp.b] << " " << v[temp.a] << '\n';
                            return 0;
                        }
                    }
                }
            }
        }
    }

    out << "-1" << '\n';

    return 0;
}