6045: Open a restaurant

Source: Internet
Author: User
Tags ming

/*

http://noi.openjudge.cn/ch0206/6045/

6045: Open a restaurant

View Submission Statistics Questions

Total time limit: 1000ms memory limit: 65536kB

Describe

Xiao Ming, a student of PKU School of Information, intends to open a restaurant after graduation. There are now N locations to choose from. Xiao Ming intends to choose the right location to open some restaurants. The n locations are arranged in a straight line. We use an integer sequence m1, M2, ... mn to represent their relative position. Because of the lot relationship, the profit of the restaurant will be different. We use PI to show the profit of opening a restaurant in Mi. In order to avoid the internal competition of their own restaurants, the distance between restaurants must be greater than K. Please help Xiao Ming to choose a plan with the biggest total profit.

Input

The standard input contains several sets of test data. The input first line is the integer t (1 <= T <= 1000), indicating that there is a T group of test data. followed by a continuous test of the T-group. Each set of test data has 3 rows,

Line 1th: Total number of places N (n < 100), distance limit K (k > 0 && k < 1000).

Line 2nd: N Locations M1, M2, ... mn (1000000 > Mi > 0 and Integer, ascending)

Line 3rd: Restaurant profit in n locations p1, p2, ... pn (> Pi > 0 and integer)

Output

Maximum possible profit for each set of test data

Sample input

2

3 11

1 2 15

10 2 30

3 16

1 2 15

10 2 30

Sample output

40

30

*/

#include <cstring>#include<iostream>#include<cstdio>using namespacestd;inta[ the];intb[ the];intf[ the];intMain () {intT; CIN>>T;  for(intk=0; k<t;k++){        intn,p; CIN>>n>>p; Memset (A,0,sizeof(a)); Memset (F,0,sizeof(f)); memset (b,0,sizeof(b));  for(intI=1; i<=n;i++) Cin>>A[i];  for(intI=1; i<=n;i++) Cin>>B[i];//f[1]=b[1];         for(intI=1; i<=n;i++) {F[i]=B[i];  for(intj=n-1; j>=1; j--){                if(a[j]+p<A[i]) {F[i]=max (f[i],f[j]+B[i]); //Break ;                }            }        }        intminn=0;  for(intI=1; i<=n;i++) {Minn=Max (F[i],minn); //cout<<f[i]<< "";} cout<<minn<<"\ n"; }} 

6045: Open a restaurant

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.