1 solutions

  • 0
    @ 2026-11-13 19:30:12

    C++ :

    #include <bits/stdc++.h>
    #define N 505
    #define M 45005
    using namespace std;
    
    int a[N],dp[M];
    int main(){
        int h,n;
        cin >> h >> n;
        for (int i = 1;i<=n;i++){
            cin >> a[i];
        }
        
        for (int i = 1;i<=n;i++){
            for (int j = h;j>=a[i];j--){
                dp[j] = max(dp[j - a[i]] + a[i],dp[j]);
            }
        }
        cout << dp[h];
        return 0;
    } 
    
    • 1

    Information

    ID
    95
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By