2892021-07-05 17:14:16k_balintBefektetéscpp14Accepted 40/4012ms2992 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,pair<ll,int>> pii;
int n,k;

ll dp[4005];
ll ans = 0;
pii t[4005];

bool cmp(pii a, pii b){
    return a.second.second > b.second.second;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int a,c; ll b; cin >> a >> b >> c;
        t[i] = make_pair(a,make_pair(b,c));
    }
    sort(t + 1, t + n + 1,cmp);

    for(int i = 1; i <= n; i++){
        int a = t[i].first;
        ll b = t[i].second.first;
        int c = t[i].second.second;
        for(int j = k - a; j > 0; j--){
            if(dp[j] != 0){
                dp[j + a] = max(dp[j + a],dp[j] + b);
                ans = max(ans,dp[j + a]);
            }
        }
        if(c + a <= k){
            dp[c + a] = max(dp[c + a],b);
            ans = max(ans,dp[c + a]);
        }
    }
    cout << ans << endl;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms2024 KiB
2Accepted0/02ms2104 KiB
3Accepted2/21ms2132 KiB
4Accepted2/21ms2144 KiB
5Accepted1/11ms2176 KiB
6Accepted2/22ms2168 KiB
7Accepted2/22ms2192 KiB
8Accepted2/22ms2168 KiB
9Accepted2/21ms2172 KiB
10Accepted2/21ms2176 KiB
11Accepted3/34ms2364 KiB
12Accepted3/34ms2348 KiB
13Accepted3/34ms2412 KiB
14Accepted3/34ms2444 KiB
15Accepted3/34ms2436 KiB
16Accepted4/44ms2432 KiB
17Accepted1/112ms2684 KiB
18Accepted1/112ms2724 KiB
19Accepted1/112ms2792 KiB
20Accepted1/112ms2848 KiB
21Accepted1/112ms2924 KiB
22Accepted1/112ms2992 KiB