Cod sursa(job #1238636)

Utilizator dica69Alexandru Lincan dica69 Data 7 octombrie 2014 13:43:42
Problema Loto Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int a[100], n, S,t,i,ok=1,t1;
int compare(int a, int b)
{
    return a < b;
}

int caut(int x)
{int p,u,t;
p=1;u=n;
while (p<=u)
{t=(p+u)/2;
if (a[t]==x) return 1;
else if (x<a[t]) u=t-1;
else p=t+1;
}
return 0;
}

int main()
{
    f >> n >> S;
    for ( i = 1; i <= n; i++)
    {
        f >> a[i];
    }
    sort(a+1, a+n+1, compare);

t=S/6+S%6-1;

while (!caut(t) && t>0) t--;
if (t==0) ok=0;
else
{t1=S-5*t;
if (!caut(t1)) ok=0;

}
if (!ok) g<<"-1";
else{
for (i=1;i<=5;i++) g<<t<<' ';
g<<t1;
}
f.close();g.close();
    return 0;
}