Pagini recente » Cod sursa (job #467225) | Cod sursa (job #810385) | Cod sursa (job #931371) | Cod sursa (job #403511) | Cod sursa (job #1803382)
#include <stdio.h>
#include <iostream>
#include <algorithm>
#define MAX 1000000
using namespace std;
int v[101], help[MAX], n;
void afis(int x){
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int l=0;l<n;l++)
if(x == v[i]+v[j]+v[l]) {
cout<<v[x]<<v[j]<<v[l];
return ;
}
}
int main(){
freopen("loto.in","r",stdin);
freopen("loto.out","w",stdout);
int s, i, j, l, m, ok;
cin>>n>>s
for(i=0;i<n;i++)
cin>>v[i];
m=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(l=0;l<n;l++){
help[m]=v[i]+v[j]+v[l];
m++;
}
sort(help, help+m);
ok=0;
i=0;
j=m-1;
while(ok==0 && i<m && j>=0){
if(help[i]+help[j]<s)
i++;
else if(help[i]+help[j]>s)
j--;
else{
afis(help[j]);
ok=1;
}
}
if(ok==0)
cout<<'-1';
return 0;
}