2872021-07-04 22:23:59Valaki2Befektetéscpp14Wrong answer 6/4050ms3424 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll maxn = 4000;
const ll maxk = 12000;

ll n, k;
ll dp[2][maxk+1];
ll max_ado[2][maxk+1];
ll ar[maxn+1];
ll ertek[maxn+1];
ll ado[maxn+1];

void solve() {
    cin >> n >> k;
    for(ll i = 1; i <= n; ++i) cin >> ar[i] >> ertek[i] >> ado[i];
    dp[1][ar[1]] = ertek[1];
    max_ado[1][ar[1]] = ado[1];
    for(ll i = 1; i < n; ++i) {
        for(ll j = 0; j <= k; ++j) {
            if(dp[(i + 1) % 2][j] < dp[i % 2][j]) {
                dp[(i + 1) % 2][j] = dp[i % 2][j];
                max_ado[(i + 1) % 2][j] = max_ado[i % 2][j];
            }
            if(dp[(i + 1) % 2][j - max_ado[i % 2][j] + max(max_ado[i % 2][j], ado[i + 1]) + ar[i + 1]] < dp[i % 2][j] + ertek[i + 1]) {
                dp[(i + 1) % 2][j - max_ado[i % 2][j] + max(max_ado[i % 2][j], ado[i + 1]) + ar[i + 1]] = dp[i % 2][j] + ertek[i + 1];
                max_ado[(i + 1) % 2][j - max_ado[i % 2][j] + max(max_ado[i % 2][j], ado[i + 1]) + ar[i + 1]] = max(max_ado[i % 2][j], ado[i + 1]);
            }
        }
    }
    ll maxi = 0;
    for(ll i = 0; i <= k; ++i) maxi = max(maxi, dp[n % 2][i]);
    cout << maxi << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/40
1Accepted0/02ms1912 KiB
2Wrong answer0/04ms2124 KiB
3Accepted2/21ms1976 KiB
4Wrong answer0/21ms1976 KiB
5Wrong answer0/11ms1976 KiB
6Accepted2/21ms2000 KiB
7Wrong answer0/21ms2000 KiB
8Wrong answer0/21ms2008 KiB
9Accepted2/21ms2012 KiB
10Wrong answer0/22ms2016 KiB
11Wrong answer0/314ms2464 KiB
12Wrong answer0/312ms2504 KiB
13Wrong answer0/313ms2512 KiB
14Wrong answer0/312ms2560 KiB
15Wrong answer0/313ms2600 KiB
16Wrong answer0/412ms2616 KiB
17Wrong answer0/145ms3120 KiB
18Wrong answer0/150ms3168 KiB
19Wrong answer0/148ms3220 KiB
20Wrong answer0/146ms3280 KiB
21Wrong answer0/145ms3196 KiB
22Wrong answer0/145ms3424 KiB