Cod sursa(job #652070)

Utilizator Marius96Marius Gavrilescu Marius96 Data 22 decembrie 2011 20:40:13
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 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;
	str(){
		a=-1;
		b=-1;
	}
	str(int x){
		a=x;
		b=-1;
	}
	str(int x,int y){
		a=x;
		b=y;
	}
	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=1;i2<=n;i2++)
			for(i3=1;i3<=n;i3++)
				w.push_back(str(v[i1]+v[i2]+v[i3],i1*101*101+i2*101+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){
			int t;
			t=it->b;
			printf("%d ",t%101);
			t/=101;
			printf("%d ",t%101);
			t/=101;
			printf("%d ",t%101);
			t=itt->b;
			printf("%d ",t%101);
			t/=101;
			printf("%d ",t%101);
			t/=101;
			printf("%d ",t%101);
			return 0;
		}
	}
	printf("-1");
	return 0;
}