Java教程

sdaaaaasdada

本文主要是介绍sdaaaaasdada,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Samsung Tire

C/C++/JAVA 3S

Samsung tire is before its launch. Prior to its product launch, it will test the safety of the tire.

In order to launch the tire, the tire must pass N test s in total.

Each test is constructed of “inflate” and “deflate”.

[inflate]40

[deflate]50

[inflate]60

[deflate]20

[inflate]30

[deflate]40

[inflate]10

[deflate]20

And has the following features:

  1. Each test starts with “inflate” first and then “deflate”.
  2. As long as all N test cases are executed, the test order can be randomly chosen.

The maximum air pressure of the Samsung tire is K.

The tire gets damaged, if the inner air pressure of the tire exceeds K or is less than 0.

For instance, given the maximum tire air pressure K=100 and the initial air pressure as 60, the tire in the following two cases will get damaged.

DAMAGED

60

[inflate]50

[deflate]40

                110

60

[inflate]20

[deflate]90

DAMAGED

                -10

Given N, K and N number of test cases, find the test order so that the initial tire air pressure can be minimized.

Print the value of the initial air pressure! (However, if there is no correct answer, print “-1”.)

For instance, suppose there are 3 test cases (N=3) as demonstrated below and the maximum tire air pressure is 100 (K=100).

[inflate]80

[deflate]95

[inflate]45

[deflate]55

[inflate]75

[deflate]30

The order of testing so that the initial tire air pressure can be minimized is shown below which is 15 in this case. (The blue numbers denote the air pressure after either “inflate” or “deflate”.)

[inflate]45

[deflate]55

[inflate]75

[deflate]30

[inflate]80

[deflate]95

15

                                                95 0                                                        75 45                                                      90 35

Below is an example of tire damage, independent of the initial air pressure and the order of testing.

(N=2, K=100)

The answer is “-1”.

[inflate]90

[deflate]30

[inflate]65

[deflate]20

[Constraints]

1<=N<=8

50<=K<=200

[Input]

The first line contains a single integer T-the number of total test cases.

From the next line on each test case is given.

Each test case consists of 3 lines.

The first line contains N, K.

The second line contains the “inflate” value for each test case and the third line contains the “deflate” value for each test case.

[Output]

Print “#t” (without the quotes), leave a blank space and print the answer.

(T refers to the test case number and starts with 1.)

[In/Output Example]

Input Example

Output Example

5

3 100

75 45 80

30 55 95

2 100

65 90

20 30

5 150

35 105 100 45 75

115 75 55 35 105

7 150

70 95 15 65 85 75 55

105 80 10 90 115 110 45

8 200

35 30 50 80 70 15 10 40

70 20 20 85 65 40 25 50

#1 15

#2 -1

#3 25

#4 -1

#5 45

这篇关于sdaaaaasdada的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!