Cod sursa(job #1204775)

Utilizator tudi98Cozma Tudor tudi98 Data 3 iulie 2014 22:06:45
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <set>
using namespace std;

struct P{
	long long x;
	int i,j,k;
	bool operator<(const P& m) const{
		return x<m.x;
	}
	bool operator==(const P& m) const{
		return x==m.x;
	}
};

int a[101];
set<P> S;
set<P>::iterator it,it1;

int main(){

	ifstream f("loto.in");
	ofstream g("loto.out");

	int n,s;
	f >> n >> s;
	for(int i=1;i<=n;i++)
		f >> a[i];

	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			for(int k=j;k<=n;k++){
				P y;
				y.x=a[i]+a[j]+a[k];
				y.i=a[i];
				y.j=a[j];
				y.k=a[k];
				S.insert(y);
			}
		}
	}

	bool ok=0;
	for(it=S.begin();it!=S.end();it++){
		P y;
		y.x=s-(it->x);
		it1=S.find(y);
		if(it1!=S.end()){
			g << it->i <<" "<< it->j <<" "<< it->k <<" ";
			g << it1->i <<" "<< it1->j <<" "<< it1->k << " ";
			ok=1; 
			break;
		}
	}		
	if(!ok) g << -1;
}