View Code of Problem 4041

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct BOOK
{
    int time, value;
} book[301];

int main(void)
{
    int max_time, n;
    while (cin >> n >> max_time)
    {
        int dp[max_time + 1] = {0};
        for (int i = 0; i < n; i++)
            cin >> book[i].time >> book[i].value;
        for (int i = 0; i < n; i++)
            for (int j = max_time; j >= book[i].time; j--)
                dp[j] = max(dp[j], dp[j - book[i].time] + book[i].value);
        cout << dp[max_time] << endl;
    }
}

Double click to view unformatted code.


Back to problem 4041