WACHOVIA - Wachovia Bank

Danilo Gheyi is a renowned bank robber. He is known worldwide for accomplishing the most profitable bank robbery, in Fortaleza, Ceará. Danilo and his friends dug a tunnel to get into the main chest. There were some bags, with different amounts of money or jewelry and weight. They had to leave about 50% of the total value, since the truck couldn't carry all the bags.

Danilo wasn't caught, and to show that he can do itall again, he is planning a robbery to one of the safer banks in USA -the Wachovia Bank. He wants your help to maximize the amount stolen, avoiding a huge loss as it happened in Fortaleza.

Write a program that, given the maximum weight the truck is ableto carry and the information about each bag in the bank, determine the maximum value that Danilo can steal.


The input consists of several instances. There is an integer N (1 ≤ N ≤ 200) in the first line; it stands for the number of instances. The first line of each instance contains two integers, K and M (8 ≤ K ≤ 1000 and 1 ≤ M ≤ 50) representing, respectively, the maximum weight the truck can handle and the amount of bags in the bank. The next M lines describe each bag with two integers A and B (8 ≤ A ≤ 200 and 1 ≤ B ≤ 25): the weight and the value of the bag, respectively.


For each instance output a sentence “Hey stupid robber, you can get P.”, and P represents the maximum value Danilo can steal.


34 5
178 12
30 1
13 7
34 8
87 6
900 1
900 25
100 10
27 16
131 9
132 17
6 5
6 23
56 21
100 25
1 25
25 25
100 2

Hey stupid robber, you can get 8.
Hey stupid robber, you can get 25.
Hey stupid robber, you can get 99.

hide comments
Peter Goggi Jr.: 2014-04-30 06:43:09

Anybody know of any crazy edge cases? Keep getting WA (using 2D long int vectors)

Anubhav Balodhi : 2014-03-31 17:43:13

this question taught me very silly mistakes about 2D arrays, but their uses are very vast... Ac at first go :-)

Last edit: 2014-03-31 17:45:35
californiagurl: 2013-12-01 05:44:36

changed long long to int,, and reduced array size,, and got AC from TLE!!!! this is crazy...

californiagurl: 2013-12-01 05:36:13

O(m*n) == TLE ,,,

Mayur Gajabi: 2013-08-29 11:40:11

don't no why i am getting wrong answer.please check my submission id 9937122.

shashank khare: 2013-08-14 16:49:09


Himanshu: 2013-06-26 11:07:55

my third DP:)
thanx to spoj for providing a database of all kind of problems......

Last edit: 2013-06-26 11:10:19
shreyash pandey: 2013-02-16 08:38:07

my 50th :)

Helpless Hindu: 2012-03-26 07:06:10

@MateusDantas: Can you please tell me why I am getting runtime error. I have taken sufficiently large array bounds and I am using standard approach.

Mateus Dantas [ UFCG ]: 2012-03-24 17:07:49

Nothing, i used only as a example of the history.

Added by:Mateus Dantas [ UFCG ]
Time limit:0.201s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Mateus Dantas