Pagini recente » Cod sursa (job #1132014) | Cod sursa (job #3299026)
#include<bits/stdc++.h>
using namespace std;
typedef long long i8;
int main(){
ifstream cin("loto.in");
ofstream cout("loto.out");
i8 n,s;
cin>>n>>s;
vector<i8>v(n);
for(i8 i = 0;i<n;i++){
cin>>v[i];
}
vector< pair<i8,vector<i8>> >sums;
i8 ct = 0;
for(i8 i =0;i<n;i++){
ct = v[i];
for(i8 j = 0;j<n;j++){
ct+=v[j];
for(i8 k = 0;k<n;k++){
ct+=v[k];
sums.push_back({ct,{i,j,k}});
ct-=v[k];
}
ct-=v[j];
}
}
sort(sums.begin(),sums.end());
i8 res = 0;
for(auto e: sums){
pair<i8,vector<i8>> p = {s-e.first,{}};
auto x = lower_bound(sums.begin(),sums.end(),p);
if(x != sums.begin() && x != sums.end() && (*x).first == p.first){
for(auto c : e.second){
cout<<v[c]<<" ";
}
for(auto c : (*x).second){
cout<<v[c]<<" ";
}
cout<<"\n";
return 0;
}
}
cout<<-1<<"\n";
return 0;
}