Cod sursa(job #2484096)

Utilizator buhaidarius@gmail.comBuhai Darius [email protected] Data 30 octombrie 2019 17:52:17
Problema Ghiozdan Scor 42
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>

#define MAXL 75005

using namespace std;

ifstream fin("ghiozdan.in");
ofstream fout("ghiozdan.out");

int dp[MAXL];

int main() {
    int n, g, x;

    fin>>n>>g;
    for(int i=0;i<n;i++){
        fin>>x;
        for(int j=g;j>x;j--){
            if(dp[j-x]>0 && (dp[j]==0 || dp[j-x]+1<dp[j]))
                dp[j] = dp[j-x]+1;
        }
        dp[x] = 1;
    }
    for(int i=g;i>=0;i--)
        if(dp[i]>0){
            fout<<i<<' '<<dp[i]<<endl;
            break;
        }
    return 0;
}