0w1

CFR 82 C. Buns ( DP, Knapsack )

Problem - 106C - Codeforces
I do seriously doubt the tag is nonsense.
Anyways, for the buns that do not require stuffings, we will do infinite knapsack.
For the buns that need stuffings, simply do multiple knapsacks.

const int MAXN = 1e3 + 3;
const int MAXM = 10 + 1;
const int MAXC = 100 + 2;

int N, M, C0, D0;
int A[ MAXM ], B[ MAXM ], C[ MAXM ], D[ MAXM ];

int dp[ MAXN ];

void solve(){
    cin >> N >> M >> C0 >> D0;
    for( int i = 0; i < M; ++i )
        cin >> A[ i ] >> B[ i ] >> C[ i ] >> D[ i ];

    for( int i = N; i >= C0; --i )
        dp[ i - C0 ] = max( dp[ i - C0 ], dp[ i ] + D0 );
    for( int i = 0; i < M; ++i )
        for( int t = 0; t < A[ i ] / B[ i ]; ++t )
            for( int j = C[ i ]; j <= N; ++j )
                dp[ j - C[ i ] ] = max( dp[ j - C[ i ] ],
                                        dp[ j ] + D[ i ] );

    int ans = 0;
    for( int i = 0; i <= N; ++i )
        ans = max( ans, dp[ i ] );

    cout << ans << "\n";
}