Cod sursa(job #2748098)

Utilizator FraNNNkieFrancesco-Gregorio Petrovici FraNNNkie Data 29 aprilie 2021 22:09:35
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <bits/stdc++.h>
#define mod 99983
using namespace std;
struct loto
{
    int x, y, z, val;
};
vector <loto> v[mod];
int nr[105], n, s, i, sum, j, k;
int main()
{
    ifstream f("loto.in");
    ofstream g("loto.out");
    f >> n >> s;
    for(i = 1; i <= n; i++)
        f >> nr[i];
    for(i = 1; i <= n; i++)
        for(j = i; j <= n; j++)
            for(k = j; k <= n; k++)
            {
                sum = nr[i] + nr[j] + nr[k];
                v[sum % mod].push_back({nr[i], nr[j], nr[k], sum});
            }
    for(i = 0; i < mod; i++)
    {
        for(j = 0; j < v[i].size(); j++)
        {
            sum = s - v[i][j].val;
            if(sum >= 0)
            {
                for(k = 0; k < v[sum % mod].size(); k++)
                {
                    if(v[sum % mod][k].val == sum)
                    {
                        g << v[i][j].x << " " << v[i][j].y << " " << v[i][j].z << " " <<  v[sum % mod][k].x << " " << v[sum % mod][k].y << " " << v[sum % mod][k].z;
                        return 0;
                    }
                }
            }
        }
    }
    g << -1;
    return 0;
}