Pagini recente » Cod sursa (job #489128) | Cod sursa (job #78532) | Cod sursa (job #426706) | Cod sursa (job #2674908) | Cod sursa (job #2094245)
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
#define bg begin
#define nd end
using namespace std;
#define maxn 1000003
int a[101];
int sums[maxn];
int n1[maxn],n2[maxn],n3[maxn];
int S,n;
int main() {
freopen("loto.in", "r", stdin);
freopen("loto.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> S;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int cnt = 0;
for (int i = 0; i < n; ++i)
for (int j = i; j < n; ++j)
for (int k = j; k < n; ++k)
sums[cnt++] = a[i] + a[j] + a[k];
sort(sums, sums + cnt);
int ptr2 = cnt-1;
for(int i=0;i<cnt;++i){
while(ptr2>=0 && sums[i] + sums[ptr2] > S) ptr2--;
if(ptr2 == -1) break;
if(sums[i] + sums[ptr2] == S){
bool first_sum = false,second_sum = false;
for(int ii=0;ii<n;++ii)
for(int j=ii;j<n;++j)
for(int k=j;k<n;++k){
if(!first_sum && a[ii] + a[j] + a[k] == sums[i]) {
first_sum = true;
cout << a[ii] << ' ' << a[j] << ' ' << a[k] << ' ';
}
if(!second_sum && a[ii] + a[j] + a[k] == sums[ptr2]){
second_sum = true;
cout << a[ii] << ' ' << a[j] << ' ' << a[k] << '\n';
}
}
return 0;
}
}
cout << -1 << '\n';
return 0;
}