Cod sursa(job #3296674)

Utilizator alyymovButoi Alexandru alyymov Data 15 mai 2025 13:38:48
Problema Loto Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.41 kb
/*****************************************
       Butoi Alexandru - Gabriel
           Colegiul National
         "Iancu de Hunedoara"
*****************************************/

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 101;
ifstream fin("loto.in");
ofstream fout("loto.out");
#if 1
#define cin fin
#define cout fout
#endif
struct pereche {
    int x, y, z;
}P[N * N * N + 5];
ll S, v[N], sum[N][N][N];
bool cmp(pereche &a, pereche &b){
    return sum[a.x][a.y][a.z] < sum[b.x][b.y][b.z];
}
int n, M;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> S;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    sort(v + 1, v + n + 1);
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            for(int k = j; k <= n; k++){
                sum[i][j][k] = v[i] + v[j] + v[k];
                P[M++] = {i, j, k};
            }
        }
    }

    sort(P, P + M, cmp);
    int lo = 0, hi = M - 1;
    while(lo <= hi){
        ll s_lo = sum[P[lo].x][P[lo].y][P[lo].z];
        ll s_hi = sum[P[hi].x][P[hi].y][P[hi].z];
        ll total = s_lo + s_hi;
        if(total == S){
            cout << v[P[lo].x] << ' ' << v[P[lo].y] << ' ' << v[P[lo].z] << ' ' << v[P[hi].x] << ' ' << v[P[hi].y] << ' ' << v[P[hi].z] << "\n";
            return 0;
        }
        if(total < S) lo++;
        else hi--;
    }
    cout << -1 << "\n";
    return 0;
}