CF (The 8th Shandong Provincial Championship, 01 Backpack + Greed)

CF

Problem Description

LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for the ith problem you can get aiditi points, where ai indicates the initial points, di indicates the points decreased per minute (count from the beginning of the contest), and ti stands for the passed minutes when you solved the problem (count from the begining of the contest).
Now you know LYD can solve the ith problem in ciminutes. He can't perform as a multi-core processor, so he can think of only one problem at a moment. Can you help him get as many points as he can?

Input

The first line contains two integers n,T(0≤n≤2000,0≤T≤5000).
The second line contains n integers a1,a2,..,an(0<ai≤6000).
The third line contains n integers d1,d2,..,dn(0<di≤50).
The forth line contains n integers c1,c2,..,cn(0<ci≤400).

Output

Output an integer in a single line, indicating the maximum points LYD can get.

Sample Input

3 10
100 200 250
5 6 7
2 4 10

Sample Output

254

Hint

Source

"Inspur Cup" Shandong Province 8th ACM College Student Programming Competition (Thanks to Qingdao University of Science and Technology)

meaning of the title

has n

Questions, each question has an initial score ai , the score of this question per unit time will decrease by di , and we can use ci Do this problem within the time to get the score, find the time T

The maximum number of points you can get.


ideas

Assume that the time required to complete each question is t

, then we will definitely choose the question with the fastest score consumption per unit time, because this will ensure that the total score will not decrease too quickly.

Assuming that each question does not automatically consume points, then we must choose the question as soon as possible.

Therefore, the formula obtained by combining the above two factors is fi=dici

, so we actually hope that the larger the d, the more in the front, and the smaller the c, the more in the front, and now c takes the reciprocal, so that the larger 1/c is, the more in the front, so just sort f directly from large to small, and then it will be naked 01 Backpack

code:

#include <bits/stdc++.h>
using namespace std;
struct node{
    int a,d,c;
    double f;
    bool operator < (const node &other)const{
        return f > other.f;
    }
}p[5100];
int dp[5100];
int main(){
    int n,T;
    while(~scanf("%d%d",&n,&T)){
        memset(dp,0,sizeof(dp));
        for(int i = 0; i < n; i++){
            scanf("%d",&p[i].a);
        }
        for(int i = 0; i < n; i++){
            scanf("%d",&p[i].d);
        }
        for(int i = 0; i < n; i++){
            scanf("%d",&p[i].c);
            p[i].f = (double)p[i].d / (double)p[i].c;
        }
        sort(p,p+n);
        int maxx = 0;
        for(int i = 0; i < n; i++){
            for(int j = T; j >= p[i].c; j--){
                dp[j] = max(dp[j],dp[j-p[i].c]+p[i].a-p[i].d*j);
                maxx = max(dp[j],maxx);
            }
        }
        printf("%d\n",maxx);
    }
    return 0;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325872376&siteId=291194637