#P16632. [GKS 2017 #F] Dance Battle

    ID: 18988 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>贪心2017双指针 two-pointerGoogle Kick Start

[GKS 2017 #F] Dance Battle

Problem Description

Your team is about to prove itself in a dance battle! Initially, your team has EE points of energy, and zero points of honor. There are NN rival teams who you must face; the i-th of these teams is the i-th in a lineup, and has a dancing skill of SiS_i.

In each round of battle, you will face the next rival team in the lineup, and you can take one of the following actions:

  1. Dance: Your team loses energy equal to the dancing skill of the rival team, and that team does not return to the lineup. You gain one point of honor. You cannot take this action if it would make your energy drop to 00 or less.
  2. Delay: You make excuses ("our shoes aren't tied!") and the rival team returns to the back of the lineup. Your energy and honor do not change.
  3. Truce: You declare a truce with the rival team, and that team does not return to the lineup. Your energy and honor do not change.
  4. Recruit: You recruit the rival team onto your team, and that team does not return to the lineup. Your team gains energy equal to the dancing skill of the rival team, but you lose one point of honor. You cannot take this action if it would make your honor drop below 00.

The battle is over when there are no more rival teams in the lineup. If you make optimal decisions, what is the maximum amount of honor you can have when the battle is over?

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow; each consists of two lines. The first line consists of two integers EE and NN: your team's energy, and the number of rival teams. The second line consists of NN integers SiS_i; the i-th of these represents the dancing skill of the rival team that is i-th in line at the start of the battle.

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum amount of honor you can have when the battle is over.

2
100 1
100
10 3
20 3 15
Case #1: 0
Case #2: 1

Hint

In Sample Case #1, there is only one rival team. You cannot dance against them because it would make your energy fall to 00, and you cannot recruit them because it would make your honor fall below 00. Delaying does not help, so the only option is to declare a truce. You finish with 00 honor.

In Sample Case #2, one optimal strategy is:

  1. Delay against the first rival team. They go to the back of the lineup.
  2. Dance against the second rival team. Your energy drops to 77, and your honor increases to 11.
  3. Recruit the third rival team. Your energy increases to 2222, and your honor decreases to 00.
  4. Dance against the first rival team (which is now at the head of the lineup again). Your energy drops to 22, and your honor increases to 11.

You finish with 11 point of honor.

Limits

1T1001 \le T \le 100.

1E1061 \le E \le 10^6.

1Si1061 \le S_i \le 10^6, for all i.

Small dataset (Test set 1 - Visible)

1N51 \le N \le 5.

Large dataset (Test set 2 - Hidden)

1N10001 \le N \le 1000.