Cod sursa(job #1140320)

Utilizator Darius15Darius Pop Darius15 Data 11 martie 2014 21:50:56
Problema Ghiozdan Scor 42
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <fstream>
#define INF 1<<31-1
using namespace std;
ifstream f("ghiozdan.in");
ofstream g("ghiozdan.out");
int nr[75001],x,j,n,gr,i,MAX;
int main()
{
    f>>n>>gr;
    nr[0]=0;
    for (i=1;i<=gr;i++)
    nr[i]=INF;
    for (i=1;i<=n;i++){
        f>>x;
        for (j=gr;j>=x;j--)
            if (nr[j-x]!=INF && nr[j]>nr[j-x]+1)
            nr[j]=nr[j-x]+1,MAX=max(MAX,j);
    }
    g<<MAX<<' '<<nr[MAX];
    return 0;
}