Pagini recente » Cod sursa (job #2971034) | Cod sursa (job #1982261) | Cod sursa (job #1355945) | Cod sursa (job #1366970) | Cod sursa (job #1793525)
#include <fstream>
#include <algorithm>
const int MMAX = 1000005;
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct loto{
int s,a,b,c;
}L[MMAX];
bool cmp(struct loto a,struct loto b)
{
if(a.s < b.s)
return true;
return false;
}
int V[105];
int Binsearch(int l,int r,const int x){
int mid;
while(l <= r){
mid = (l + r) >> 1;
if(L[mid].s == x)
return mid;
if(L[mid].s < x){
l = mid + 1;
} else {
r = mid - 1;
}
}
return -1;
}
int main()
{
ios :: sync_with_stdio(false);
fin.tie(NULL);
int n,S,m = 0,poz;
fin >> n >> S;
for(int i = 1; i <= n; i++)
fin >> V[i];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
for(int k = 1; k <= n; k++){
L[++m].s = V[i] + V[j] + V[k];
L[m].a = V[i]; L[m].b = V[j]; L[m].c = V[k];
}
sort(L + 1, L + m + 1, cmp);
for(int i = 1; i <= m; i++){
poz = Binsearch(1,m,S - L[i].s);
if(poz != -1){
fout << L[i].a << " " << L[i].b << " " << L[i].c << " " << L[poz].a << " " << L[poz].b << " " << L[poz].c;
return 0;
}
}
fout << -1;
return 0;
}