Pagini recente » Cod sursa (job #2943871) | Cod sursa (job #1293203) | Cod sursa (job #869153) | Cod sursa (job #1176900) | Cod sursa (job #1094709)
#include <fstream>
#define INF 0x3f3f3f3f
using namespace std;
ifstream is("ghiozdan.in");
ofstream os("ghiozdan.out");
void Scrie(int x);
int n, S, x, a[75001], p[75001], nr;
int main()
{
is >> n >> S;
for ( int i = 1; i <= S; ++i )
a[i] = INF;
for ( int i = 0; i < n; ++i )
{
is >> x;
for ( int j = S - x; j >= 0; --j )
{
if ( a[j + x] > a[j] + 1 )
{
a[j+x] = a[j] + 1;
p[j+x] = j;
}
}
}
nr = S;
while ( a[nr] == INF )
nr--;
os << nr << ' ' << a[nr] << '\n';
Scrie(nr);
is.close();
os.close();
return 0;
}
void Scrie(int x)
{
if ( x == 0 ) return;
Scrie(p[x]);
os << x - p[x] << '\n';
}