Cod sursa(job #3129377)

Utilizator AndreiKatsukiAndrei Dogarel AndreiKatsuki Data 14 mai 2023 11:33:31
Problema Loto Scor 75
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 105;
int n, S, a[NMAX];
map<int, vector<int>> mp;

int main(){
    f >> n >> S;
    for(int i = 1; i <= n; ++i){
        f >> a[i];
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            for(int k = 1; k <= n; ++k){
                mp[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
            }
        }
    }
    bool ok = false;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            for(int k = 1; k <= n; ++k){
                int s = a[i] + a[j] + a[k];
                if(mp.find(S - s) != mp.end()){
                    ok = true;
                    g << mp[S - s][0] << " " << mp[S - s][1] << " " << mp[S - s][2] << " " << a[i] << " " << a[j] << " " << a[k];
                    return 0;
                }
            }
        }
    }
    if(!ok){
        g << -1;
    }
    return 0;
}