Pagini recente » Cod sursa (job #2627068) | Cod sursa (job #987182) | Cod sursa (job #705934) | Monitorul de evaluare | Cod sursa (job #2094240)
#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];
n1[cnt] = a[i];
n2[cnt] = a[j];
n3[cnt] = a[k];
cnt++;
}
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){
vector<int> sol;
sol.pb(n1[i]);sol.pb(n2[i]);sol.pb(n3[i]);
sol.pb(n1[ptr2]);sol.pb(n2[ptr2]);sol.pb(n3[ptr2]);
sort(sol.begin(),sol.end());
for(int i=0;i<6;++i){
cout << sol[i] << ' ';
}
cout << '\n';
return 0;
}
}
cout << -1 << '\n';
return 0;
}