3342021-10-13 22:06:46rmlanBefektetéscpp11Accepted 40/4029ms2892 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define ll long long
#define tc int _TC_; cin >> _TC_; while(_TC_--)
using namespace std;
bool comp(vector<int> a, vector<int> b){
    return a[2] < b[2];
}
int main(){
    int n,k;
    cin >> n >> k;
    vector<vector<int> > a(n);
    for(int i = 0; i < n;i++){
        a[i].resize(3);
        int p,v,t;
        cin >> p >> v >> t;
        a[i][0]=p;
        a[i][1]=v;
        a[i][2]=t;
    }
    sort(a.begin(), a.end(), comp);
    vector<int> b(k+1), b2(k+1);
    int me=0;
    for(int i = 1; i <= k;i++){
        b[i]=0;
        b2[i]=0;
    }
    for(int i = 0; i < n; i++){
        if(a[i][0]+a[i][2] <= k){
            b2=b;
            for(int j = k-a[i][0]-a[i][2]; j >=1 ; j--){

                if(b[j] != 0 && j+a[i][0]+a[i][2] <= k){
                    b2[j+a[i][0]] = max(b[j]+a[i][1], b[j+a[i][0]]);
                    me=max(me, b2[j+a[i][0]]); //cout << "\n\n\n\n" << j << "     " << b[j];
                    //cout << me << endl;
                }
            }
            b=b2;
            b[a[i][0]]=max(b[a[i][0]], a[i][1]);
            me=max(me, b[a[i][0]]);

        }
    }
    /*cout << "\n\n\n\n\n";
    for(int i = 0; i <= k; i++){
        cout << b[i] << endl;
    }*/
    cout << me << endl;
}

SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1776 KiB
2Accepted0/04ms1980 KiB
3Accepted2/21ms1864 KiB
4Accepted2/21ms1872 KiB
5Accepted1/12ms1872 KiB
6Accepted2/22ms1888 KiB
7Accepted2/21ms1892 KiB
8Accepted2/21ms1900 KiB
9Accepted2/21ms1900 KiB
10Accepted2/21ms1904 KiB
11Accepted3/310ms2152 KiB
12Accepted3/39ms2176 KiB
13Accepted3/39ms2204 KiB
14Accepted3/39ms2236 KiB
15Accepted3/312ms2268 KiB
16Accepted4/49ms2300 KiB
17Accepted1/128ms2584 KiB
18Accepted1/129ms2640 KiB
19Accepted1/128ms2696 KiB
20Accepted1/128ms2764 KiB
21Accepted1/128ms2828 KiB
22Accepted1/129ms2892 KiB