Pagini recente » Cod sursa (job #2405415) | Cod sursa (job #1364815) | Cod sursa (job #761234) | Cod sursa (job #3257465) | Cod sursa (job #2625141)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
struct loto
{
int a, b, c, sum;
};
bool cmp(loto x, loto y)
{
return x.sum < y.sum;
}
loto d[1000001];
int main()
{
ifstream f("loto.in");
ofstream g("loto.out");
int v[101], ct = 0, n, s, i, j, k;
f>>n>>s;
for(int i=1; i<=n; i++)
f>>v[i];
for(i=1; i<=n; i++)
for(j=i; j<=n; j++)
for(k=j; k<=n; k++)
{
d[++ct].a = v[i];
d[ct].b = v[j];
d[ct].c = v[k];
d[ct].sum = v[i]+v[j]+v[k];
}
sort(d + 1, d + ct + 1, cmp);
int x = 1, y = ct, gasit = 0;
while(x <= y)
{
if(d[x].sum + d[y].sum == s)
{
gasit = 1;
g<<d[x].a<<" "<<d[x].b<<" "<<d[x].c<<" "<<d[y].a<<" "<<d[y].b<<" "<<d[y].c;
return 0;
}
else if(d[x].sum + d[y].sum<s)
x++;
else
y--;
}
if(!gasit)
g<<-1;
return 0;
}