Pagini recente » Cod sursa (job #1467522) | Cod sursa (job #468134) | Cod sursa (job #488430) | Cod sursa (job #1461287) | Cod sursa (job #2508717)
#include <iostream>
#include <algorithm>
#include <cmath>
#include <fstream>
using namespace std;
bool comp ( int x, int y ) {
return ( y < x );
}
int main()
{
ifstream fin("loto.in");
ofstream fout("loto.out");
int n, s, sir[101], sol[10];
fin>>n>>s;
for ( int i = 1; i <= n; ++i ) {
fin>>sir[i];
}
sort(sir + 1, sir + 1 + n, comp);
int stop = 0, i = 1, j = 1;
while ( stop == 0 ) {
if ( s - sir[i] >= sir[n] * (n - i) ) {
s = s - sir[i];
sol[j] = sir[i];
++j;
} else {
++i;
}
if ( s == 0 || i > n )
stop = 1;
}
if ( j == 7 ) {
for ( int x = 1; x <= 6; ++x )
fout<<sol[x]<<" ";
} else {
fout<<-1;
}
return 0;
}