Cod sursa(job #1292105)

Utilizator romircea2010FMI Trifan Mircea Mihai romircea2010 Data 13 decembrie 2014 17:31:06
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.53 kb
#include <fstream>
#include <vector>

using namespace std;

const int NMax = 110, MOD = 666013, SMax = 600000000;

struct str
{
    int sum, x, y, z;
    str ()
    {
        this -> sum = this -> x = this -> y = this -> z = 0;
    }
    str (const int sum, const int x, const int y, const int z)
    {
        this -> sum = sum;
        this -> x = x;
        this -> y = y;
        this -> z = z;
    }
};

int N, S;
int a[NMax];
vector <str> H[MOD];

int main()
{
    ifstream f ("loto.in");
    f >> N >> S;
    for (int i = 1; i <= N; ++ i)
        f >> a[i];
    f.close();
    for (int i = 1; i <= N; ++ i)
        for (int j = i; j <= N; ++ j)
            for (int k = j; k <= N; ++ k)
            {
                int nowsum = a[i] + a[j] + a[k];
                int srch = S - nowsum;
                if (srch < 0)
                    continue;
                int code = srch % MOD;
                for (vector <str> :: iterator it = H[code].begin(); it != H[code].end(); ++ it)
                {
                    if (it -> sum == srch)
                    {
                        ofstream g ("loto.out");
                        g << i << " " << j << " " << k << " " << it -> x << " " << it -> y << " " << it -> z << "\n";
                        g.close();
                        return 0;
                    }
                }
                H[nowsum % MOD].push_back(str(nowsum, i, j, k));
            }
    ofstream g ("loto.out");
    g << "-1\n";
    g.close();
    return 0;
}