Cod sursa(job #298551)

Utilizator robigiirimias robert robigi Data 6 aprilie 2009 10:58:40
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int n, s;
int v[105];
struct Numere
{      int a, b, c, sum;
};

vector <Numere> a;


int cmp(const Numere &x, const Numere &y)
{   return x.sum<y.sum;
}

int main()
{   freopen("loto.in", "r", stdin);
    freopen("loto.out", "w", stdout);
	int i, j, k;
	scanf("%d %d", &n, &s);
	for (i=1; i<=n; i++) scanf("%d", &v[i]);
	
	for (i=1; i<=n; i++)
	    for (j=1; j<=n; j++)
		    for (k=j; k<=n; k++)
			{   Numere x;
			    x.a=v[i]; x.b=v[j]; x.c=v[k];
				x.sum=v[i]+v[j]+v[k];
				a.push_back(x);
			}
	sort (a.begin(), a.end(), cmp);
	
	i=0;
	j=a.size()-1;
	
	while (i<=j)
	{      int dif=s-a[i].sum;
	       while (a[j].sum>dif) j--;
		   if (a[j].sum==dif)
		   {  printf("%d %d %d %d %d %d\n", a[i].a, a[i].b, a[i].c, a[j].a, a[j].b, a[j].c);
		      return 0;
		   }
		   i++;
	}
	printf("-1\n");
	return 0;
	
}