Cod sursa(job #3163692)

Utilizator butasebiButa Gabriel-Sebastian butasebi Data 31 octombrie 2023 21:33:58
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
//Buta Gabriel-Sebastian
//University of Bucharest

#include<bits/stdc++.h>
#define PI 3.14159265358979323846
#define MOD 998244353
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int ii, tc, n, S, v[105];
unordered_map<int, pair<int,pair<int,int>>> VALID;
void read()
{
    f >> n >> S;
    for(int i = 1; i <= n; i ++)
        f >> v[i];
}
void solve()
{
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= n; j ++)
            for(int k = 1; k <= n; k ++)
            {
                int sum = v[i] + v[j] + v[k];
                VALID[sum].first = v[i];
                VALID[sum].second.first = v[j];
                VALID[sum].second.second = v[k];
            }

    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= n; j ++)
            for(int k = 1; k <= n; k ++)
            {
                int sum = S - (v[i] + v[j] + v[k]);
                if(VALID.find(sum) != VALID.end())
                {
                    g << v[i] << " " << v[j] << " " << v[k] << " " << VALID[sum].first << " " << VALID[sum].second.first << " " << VALID[sum].second.second << "\n";
                    return;
                }

            }
    g << "-1";
}
void write()
{
}
int main()
{
    //cin >> tc;
    tc = 1; //test cases
    for(ii = 1; ii <= tc; ii ++)
    {
        read();
        solve();
        write();
    }

    return 0;
}