Cod sursa(job #2809437)

Utilizator DordeDorde Matei Dorde Data 27 noiembrie 2021 00:01:59
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int const N = 101;
int v [N];
unordered_map <int , tuple<int , int , int>> asked;
int main()
{
    int n , s;
    fin >> n >> s;
    for(int i = 1 ; i <= n ; ++ i)
        fin >> v [i];
    for(int i = 1 ; i <= n ; ++ i)
        for(int j = 1 ; j <= n ; ++ j)
            for(int k = 1 ; k <= n ; ++ k)
                asked [s - v[i] - v[j] - v[k]] = {i , j , k};
    for(int i = 1 ; i <= n ; ++ i)
        for(int j = 1 ; j <= n ; ++ j)
            for(int k = 1 ; k <= n ; ++ k)
                if (asked.count (v[i] + v[j] + v[k])){
                    fout << v [i] << ' ' << v [j] << ' ' << v [k] << ' ';
                    int a , b , c;
                    tie(a , b , c) = asked[v [i] + v [j] + v [k]];
                    fout << a << ' ' << b << ' ' << c << '\n';
                    fin.close();
                    fout.close();
                    return 0;
                }
    fout << "-1\n";
    fin.close();
    fout.close();
    return 0;
}