Uva672

Source: Internet
Author: User

 

Gangsters

NGangsters are going to a restaurant.I-Th gangster comes at the timeTIAnd hasProsperity PI. The door of the restaurant hasK+ 1 states of openness expressed by the integers in the range [0,K]. The state of openness can change by one in one unit of time; I. e. it either opens by one, closes by one or remains the same. at the initial moment of time the door is closed (state 0 ). theI-Th gangster enters the restaurant only if the door is opened specially for him, I. e. when the state of openness coincides with hisStoutnessSI. If at the moment of time when the gangster comes to the restaurant the state of openness is not equal to his stoutness, then the gangster goes away and never returns.

 


The restaurant works in the interval of time [0,T].

 


The goal is to gather the gangsters with the maximal total prosperity in the restaurant by opening and closing the door appropriately.

 

Input

The first line of the input is an integer M, then a blank line followed by M datasets. There is a blank line between datasets.

The first line of each dataset contains the valuesNK, AndT, Separated by spaces .()

The second line of the dataset contains the moments of time when gangsters come to the restaurant, separated by spaces. ()

The third line of the dataset contains the values of the prosperity of gangsters, separated by spaces. ()

The forth line of the dataset contains the values of the stoutness of gangsters, separated by spaces. ()

 


All values in the input file are integers.

 

Output

For each dataset, print the single integer-the maximal sum of prosperity of gangsters in the restaurant. in case when no gangster can enter the restaurant the output shocould be 0. print a blank line between datasets.

 

Sample Input

 

14 10 2010 16 8 1610 11 15 110 7 1 8

 

Sample Output
26
This is to give a door, each time period can increase by 1 unit to reduce by 1 unit, without increasing or decreasing, (maximum k) then there are n people, when each person reaches this point at a certain time point, when the width of the door is equal to that person, this person can go in.
Everyone has a certain wealth value. The maximum wealth value for entering this door is how big it is. At the same time, there can be people going in.
# Include <iostream> # include <cstdio> # include <algorithm> # include <string. h ># include <vector> using namespace std; typedef long ll; struct point {int ti, Si, Pi;} P [105]; int dp [30005] [105]; vector <int> F [30005]; int main () {int cas; scanf ("% d", & cas); int N, k, T; for (int cc = 1; cc <= cas; ++ cc) {scanf ("% d", & N, & K, & T); for (int I = 0; I <= T; ++ I) {F [I]. clear () ;}for (int I = 0; I <N; ++ I) {scanf ("% d", & P [I]. ti ); F [P [I]. ti]. push_back (I) ;}for (int I = 0; I <N; ++ I) scanf ("% d", & P [I]. pi); for (int I = 0; I <N; ++ I) scanf ("% d", & P [I]. si); memset (dp,-1, sizeof (dp); int ans = 0; dp [0] [0] = 0; for (int I = 1; I <= T; ++ I) {int sz = F [I]. size (); for (int j = 0; j <sz; ++ j) {int loc = F [I] [j]; int Si = P [loc]. si; if (dp [I] [Si]! =-1) {dp [I] [Si] + = P [loc]. Pi; continue;} if (Si-1> = 0 & dp [i-1] [Si-1]! =-1) {dp [I] [Si] = max (dp [I] [Si], dp [i-1] [Si-1] + P [loc]. pi);} if (dp [i-1] [Si]! =-1) {dp [I] [Si] = max (dp [I] [Si], dp [i-1] [Si] + P [loc]. pi);} if (Si + 1 <= K & dp [i-1] [Si + 1]! =-1) {dp [I] [Si] = max (dp [I] [Si], dp [i-1] [Si + 1] + P [loc]. pi);} ans = max (dp [I] [j], ans);} for (int j = 0; j <= K; ++ j) {if (J-1> = 0 & dp [i-1] [j-1]! =-1) dp [I] [j] = max (dp [I] [j], dp [i-1] [j-1]); if (dp [i-1] [j]! =-1) dp [I] [j] = max (dp [I] [j], dp [i-1] [j]); if (j + 1 <= K & dp [i-1] [j + 1]! =-1) dp [I] [j] = max (dp [I] [j], dp [i-1] [j + 1]); ans = max (dp [I] [j], ans) ;}} printf ("% d \ n", ans); if (cc! = Cas) printf ("\ n");} return 0 ;}
View Code

 

Uva672

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.