Cod sursa(job #2895788)

Utilizator NicuDirvaDirva Nicolae NicuDirva Data 29 aprilie 2022 14:38:55
Problema Loto Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

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

const int p = 666013;

struct triplet{
    int x, y, z;
} suma[p + 2];

int main()
{
int n, i, j, k, v[101];
triplet t;
long int s, aux;
fin >> n >> s;
for(i = 0; i < n; i++)
    fin >> v[i];

for(int i = 0; i < n; i++)
    for(int j = i; j < n; j++)
        for(int k = j; k < n; k++)
        {
            t.x = v[i]; t.y = v[j]; t.z = v[k];
            suma[(v[i] + v[j] + v[k]) % p] = t;
        }
for(int i = 0; i < n; i++)
    for(int j = i; j < n; j++)
        for(int k = j; k < n; k++)
        {
            aux = (s - v[i] - v[j] - v[k]) % p;
            if(aux < 0) 
                aux += p;
            if(suma[aux].x)
            {
                if(v[i] + v[j] + v[k] + suma[aux].x + suma[aux].y + suma[aux].z == s)
                {
                    fout << v[i] << ' ' << v[j] << ' ' << v[k] << ' ' << suma[aux].x << ' ' << suma[aux].y << ' ' << suma[aux].z;
                    return 0;
                }
            }
        }
fout << -1;
return 0;
}