2862021-07-04 22:22:47Valaki2Befektetéscpp14Wrong answer 6/4048ms3012 KiB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 4000;
const int maxk = 12000;

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

void solve() {
    cin >> n >> k;
    for(int 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(int i = 1; i < n; ++i) {
        for(int 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]);
            }
        }
    }
    int maxi = 0;
    for(int 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/02ms1852 KiB
2Wrong answer0/04ms2088 KiB
3Accepted2/21ms1972 KiB
4Wrong answer0/21ms1984 KiB
5Wrong answer0/11ms1984 KiB
6Accepted2/21ms2048 KiB
7Wrong answer0/21ms2048 KiB
8Wrong answer0/21ms2052 KiB
9Accepted2/21ms2060 KiB
10Wrong answer0/21ms2068 KiB
11Wrong answer0/313ms2288 KiB
12Wrong answer0/312ms2336 KiB
13Wrong answer0/313ms2352 KiB
14Wrong answer0/312ms2396 KiB
15Wrong answer0/312ms2428 KiB
16Wrong answer0/412ms2452 KiB
17Wrong answer0/143ms2708 KiB
18Wrong answer0/141ms2764 KiB
19Wrong answer0/148ms2816 KiB
20Wrong answer0/143ms2940 KiB
21Wrong answer0/146ms2988 KiB
22Wrong answer0/143ms3012 KiB