Cod sursa(job #3222602)

Utilizator PescarusTanislav Luca Andrei Pescarus Data 10 aprilie 2024 23:18:28
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <unordered_map>

using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct triplet{
    int x, y, z;
};
const int nmax = 105;
int a[nmax];
unordered_map<int, triplet> mp;
int n, s;

int main(){
    ios::sync_with_stdio(0);
    f.tie(0);
    f >> n >> s;
    for(int i = 1; i <= n; i++){
        f >> a[i];
    }

    //populam mai intai mapul cu toate posibilitatile de sume de 3
    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]};
            }
        }
    }

    //acum facem ca in cazul problemei 1 de pe leetcode doar ca nu mai e in cazul micut suntem in cazul cu 3 numere si 3 numere

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                int dif = s - a[i] - a[j] - a[k];
                if(mp.count(dif)){
                    g << a[i] << ' ' << a[j] << ' ' << a[k] << ' ' << mp[dif].x << ' ' << mp[dif].y << ' ' << mp[dif].z << '\n';
                    return 0;
                }
            }
        }
    }
    g << -1;
    return 0;
}