제출 #780551

#제출 시각아이디문제언어결과실행 시간메모리
780551andecaandeciKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms1876 KiB
#include<bits/stdc++.h>
using namespace std;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int t, n;
int l[100004], e[100004], k[100004];
signed main() {
    ioss;
    cin >> t >> n;
    for(int i = 0; i < n; i++) cin >> l[i] >> e[i] >> k[i];

    int dp[n+1][t+1] = {};
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= t; j++) {
            if(i == 0 || j == 0) dp[i][j] = 0;
            else {
                for(int x = 1; x <= k[i-1]; x++) {
                    if(x*e[i-1] > j) break;
                    dp[i][j] = max(dp[i-1][j-x*e[i-1]]+x*l[i-1], dp[i-1][j]);
                }
            }
        }
    }
    cout << dp[n-1][t] << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...