Pagini recente » Cod sursa (job #861324) | Cod sursa (job #191147) | Cod sursa (job #1395329) | Cod sursa (job #786494) | Cod sursa (job #2957972)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");
int *a, *b;
int n, g;
int main()
{
fin >> n >> g;
if (g == 0)
{
fout << "0 0";
return 0;
}
a = new int[75002]();
b = new int[75002]();
for (int i = 1; i <= n; i++)
{
int x;
fin >> x;
x = min(x, g + 1);
for (int j = 1; j < x; j++)
b[j] = a[j];
b[x] = 1;
for (int j = x + 1; j <= g; j++)
{
b[j] = a[j];
if (a[j - x] && (!b[j] || b[j] > a[j - x] + 1))
b[j] = a[j - x] + 1;
}
swap(a, b);
}
int i = g;
while (i >= 1 && !a[i])
i--;
fout << i << ' ' << a[i] << '\n';
return 0;
}