Banner Home Page DIY Contests Problems Ranklist Status Statistics
pdf版的题目下载:初赛goo.gl/rfbDY,决赛goo.gl/fNcyY。K题请使用GUN C++提交,用VC/VC++提交会返回RE。

Quantity Of The Stones

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 129   Accepted Submission(s) : 27

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

  xysDavidCN wants to fool two fools Jeflie and BandBand, so he designs a game to play with them.
  xysDavidCN puts n piles of stones on the floor. Then he asks BandBand to observe the stones. Jeflie is not allowed to see the stones in the game.
  Then, BandBand should estimate and tell Jeflie how many stones each pile has at most. And xysDavidCN will give BandBand m chances to estimate and tell Jeflie messages.
  The message must be "the total amount from the i-th pile to the j-th pile is at least k stones".
  After that, Jeflie should tell xysDavidCN how many stones of all the n piles at least.
  Because BandBand is fool, he may make some wrong estimates leading Jeflie not figure it out.

Input

  There are multiple test cases. The first line contains an integer T (T<=100), indicating the index of the test cases.
  T test cases follow. Each test case contains two integers n and m (0<n<=1000, 0<m<=10000) in the first line.
  Then follow n integers next line. The i-th integer indicates that there are at most si stones in the i-th pile, each integer will not exceed 10^9.
  Next m lines contain 3 integers i, j, k (0<i<j<=n, 0<k<10^9) each line. It means that the total amount of stones from the i-th pile to the j-th pile is at least k.

Output

  For each test case, output "Case #D: " first, D is the index of the test case.
  If Jeflie can figure out how many stones of all the n piles at least, output the least summation of the n piles stones. Output "Foolish BandBand!" otherwise.

Sample Input

2
3 2
10 20 10
1 2 11
2 3 13
3 1
1 2 3
2 3 6

Sample Output

Case #1: 13
Case #2: Foolish BandBand!

Source

华南师范大学·2012年ACM程序设计竞赛·决赛

Statistic | Submit | Back