# Cod sursa(job #428443)

Utilizator Data 29 martie 2010 11:49:17 Loto 5 cpp done Arhiva de probleme 1.04 kb
``````#include <fstream>
#include <vector>

#define SMAX 1000010
#define NMAX 127
using namespace std;

ifstream fin("loto.in");
ofstream fout("loto.out");

vector<int> A;
int  N, NR[NMAX], S;

void Afiseaza(int x)
{
int i, j, k;

for (i = 1; i <= N; i++)
for (j = 1; j<= N; j++)
for (k = 1; k <= N; k++)
if( NR[i] + NR[j] + NR[k] == x )
fout << NR[i] <<' ' <<NR[j] <<' ' <<NR[k] <<' ', i = j = k = N + 1;
}

int main()
{

int i, j, k, st, end, m;

fin >>N >>S;

for (i = 1; i <= N; i++)
fin >>NR[i];

for (i = 1; i <= N; i++)
for (j = 1; j<= N; j++)
for (k = 1; k <= N; k++)
A.push_back( NR[i] + NR[j] + NR[k]);

for (i = 0; i < A.size(); i++)
{
st = 0, end = A.size(), m;
while (st <= end)
{
m = (st + end) / 2;

if (A[m] > S - A[i]) end = m - 1;
if (A[m] < S - A[i]) st = m + 1;

if (A[m] + A[i] == S)
{
Afiseaza(A[m]);
Afiseaza(A[i]);

fout.close();
return 0;
}
}
}
fout <<"-1";
fout.close();
return 0;
}
``````