Cod sursa(job #652074)

Utilizator Marius96Marius Gavrilescu Marius96 Data 22 decembrie 2011 20:43:21
Problema Loto Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

int i,i1,i2,i3,i4,i5,i6,n,s;
int v[105];
struct str{
	int a,b,c,d;
	str(){
		a=-1;
		b=-1;
	}
	str(int x){
		a=x;
		b=-1;
	}
	str(int x,int y,int z,int t){
		a=x;
		b=y;
		c=z;
		d=t;
	}
	bool operator==(str s){
		return a==s.a;
	}
	bool const operator<(const str s)const{
		return a<s.a;
	}
};
vector<str> w;

int main(){
	freopen("loto.in","r",stdin);
	freopen("loto.out","w",stdout);
	scanf("%d%d",&n,&s);
	for(i=1;i<=n;i++)
		scanf("%d",v+i);
	for(i1=1;i1<=n;i1++)
		for(i2=i1+1;i2<=n;i2++)
			for(i3=i2+1;i3<=n;i3++)
				w.push_back(str(v[i1]+v[i2]+v[i3],v[i1],v[i2],v[i3]));
	sort(w.begin(),w.end());
	for(vector<str>::iterator it=w.begin();it!=w.end();it++){
		vector<str>::iterator itt=lower_bound(w.begin(),w.end(),s-it->a);
		if(it->a+itt->a==s){
			printf("%d %d %d %d %d %d",it->b,it->c,it->d,itt->b,itt->c,itt->d);
			return 0;
		}
	}
	printf("-1");
	return 0;
}