Pagini recente » Cod sursa (job #447127) | Cod sursa (job #1327956) | Cod sursa (job #2609226) | Cod sursa (job #994315) | Cod sursa (job #856996)
Cod sursa(job #856996)
#include<fstream>
#include<algorithm>
using namespace std;
struct e{int s,a,b,c;}sol[700000];
int a[105],n,s,acum,nr;
ifstream in("loto.in"); ofstream out("loto.out");
bool cmp(e x, e y){
if(x.s>y.s) return 0; return 1;
}
void afis(int x, int y){
out<<sol[x].a<<' '<<sol[x].b<<' '<<sol[x].c<<' '<<sol[y].a<<' '<<sol[y].b<<' '<<sol[y].c<<'\n';
}
int main(){
in>>n>>s;
for(int i=1;i<=n;++i) in>>a[i];
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
for(int k = j; k <= n; k++){
sol[++nr].s = a[i] + a[j] + a[k];
sol[nr].a = a[i];
sol[nr].b = a[j];
sol[nr].c = a[k];
}
sort(sol+1,sol+nr+1,cmp);
int high = nr, low = 1;
while(low <= high){
if((sol[low].s + sol[high].s) > s)
high--;
else if(sol[low].s + sol[high].s < s)
low++;
else
break;
}
if(low > high)
out << -1;
else
out << sol[low].a << " " << sol[low].b << " " << sol[low].c << " " << sol[high].a << " " << sol[high].b << " " << sol[high].c;
out.close(); return 0;
}