Pagini recente » Cod sursa (job #1680132) | Cod sursa (job #1563214) | Cod sursa (job #1567866) | Cod sursa (job #2725938) | Cod sursa (job #1240470)
#include<fstream>
using namespace std;
ifstream f("ghiozdan.in");
ofstream g("ghiozdan.out");
bool ok[20002];
int ob[75001], N, G, g_obiect, maxim, ultim[20002], suma, nr, i, j;
int main()
{
f>>N>>G;
ok[0]=1;
for(i=1;i<=N;i++)
{
f>>g_obiect;
for(j=G;j>=0;j--)
if(ok[j]==1)
if(j+g_obiect<=G)
{
ok[j+g_obiect]=1;
if(ob[j+g_obiect]==0)
{
ob[j+g_obiect]=ob[j]+1;
}
else if(ob[j+g_obiect]>ob[j]+1)
{
ob[j+g_obiect]=ob[j]+1;
}
}
}
for(i=G;i>=0;i--)
if(ok[i]==1)
{
g<<i<<" "<<ob[i]<<endl;
suma=i; nr=ob[i]; break;
}
return 0;
}