Pagini recente » Cod sursa (job #1247389) | Cod sursa (job #789490) | Cod sursa (job #1895921) | Cod sursa (job #1164282) | Cod sursa (job #3184741)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("loto.in");
ofstream cout("loto.out");
struct Pereche{
int suma;
int a;
int nr1;
int nr2;
int nr3;
};
Pereche A[150000];
int v[3];
bool cmp(Pereche a,Pereche b){
if(a.suma<b.suma){
return true;
}
return false;
}
int main()
{
int n,s;
cin>>n>>s;
int a,b,c;
cin>>v[0]>>v[1]>>v[2];
int cnt=0,sum=0;
for (int i = 0; i < 3; i++) {
sum=sum+v[i];
for (int j = 0; j < 3; j++) {
sum=sum+v[j];
for (int k = 0; k < 3; k++) {
sum=sum+v[k];
A[cnt].suma=sum;
A[cnt].nr1=v[i];
A[cnt].nr2=v[j];
A[cnt].nr3=v[k];
cnt++;
sum=sum-v[k];
}
sum=sum-v[j];
}
sum=sum-v[i];
}
sort(A,A+cnt,cmp);
bool ok=false;
for (int i = 0; i < cnt-1; i++) {
for(int j=i;j <cnt;j++){
if(A[i].suma+A[j].suma==s){
cout<<A[i].nr1<<" "<<A[i].nr2<<" "<<A[i].nr3<<" "<<A[j].nr1<<" "<<A[j].nr2<<" "<<A[j].nr3;
ok=true;
break;
}
}
if(ok==true)break;
}
if(ok==false)cout<<"-1";
return 0;
}