Cod sursa(job #2663421)

Utilizator kywyPApescu tiGEriu kywy Data 26 octombrie 2020 12:48:00
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include<fstream>
#include<map>
using namespace std;

int nr[107];
map<int, int> v;

int main()
{	
	ifstream in("loto.in");
	ofstream out("loto.out");
	int n, s;
	in>>n>>s;
	for(int i=1; i<=n; ++i)
	{
		in>>nr[i];
	}
	for(int i=1; i<=n; ++i)
	{
		for(int j=1; j<=n; ++j)
		{
			v[nr[i]+nr[j]]=1;
		}
	}
	int s1=0, s2=0, s3=0;
	for(map<int, int>::iterator i = v.begin(); i!=v.end(); ++i)
	{
		s1=i->first;
		for(map<int, int>::iterator j = v.begin(); j!= v.end(); ++j)
		{
			s2=j->first;
			if(v.find(s-s1-s2)!=v.end())
			{
				s3=s-s1-s2;
				for(int t1=1; t1<=n; ++t1)
				{
					for(int t2=1; t2<=n; ++t2)
					{
						if(t1+t2==s1&&s1)
						{
							s1=0;
							out<<t1<<" "<<t2<<" ";
						}
						if(t1+t2==s2&&s2)
						{
							s2=0;
							out<<t1<<" "<<t2<<" ";
						}
						if(t1+t2==s3&&s3)
						{
							s3=0;
							out<<t1<<" "<<t2<<" ";
						}
						if(s1==0&&s2==0&&s3==0) return 0;
					}
				}
			}
		}	
	}
	out<<"-1";	
	return 0;	
}