FARIDA - Princess Farida


Once upon time there was a cute princess called Farida living in a castle with her father, mother and uncle. On the way to the castle there lived many monsters. Each one of them had some gold coins. Although they are monsters they will not hurt. Instead they will give you the gold coins, but if and only if you didn't take any coins from the monster directly before the current one. To marry princess Farida you have to pass all the monsters and collect as many coins as possible. Given the number of gold coins each monster has, calculate the maximum number of coins you can collect on your way to the castle.

Input

The first line of input contains the number of test cases. Each test case starts with a number N, the number of monsters, 0 <= N <= 10^4. The next line will have N numbers, number of coins each monster has, 0 <= The number of coins with each monster <= 10^9. Monsters described in the order they are encountered on the way to the castle.

Output

For each test case print “Case C: X” without quotes. C is the case number, starting with 1. X is the maximum number of coins you can collect.

Example

Input:
2
5
1 2 3 4 5
1
10

Output:
Case 1: 9
Case 2: 10

hide comments
xceptor: 2015-07-26 20:06:49

nice Question. pay attention on this line - "but if and only if you didn't take any coins from the monster directly before the current one."

sourcedelica: 2015-07-25 23:00:30

It looks like the time limit is too short for Scala program. It needs to be at least 2-3 seconds - FARIDA is 1.237s.
http://www.spoj.com/forum/viewtopic.php?f=43&t=7731&sid=bf04f416bf724750045a192ee78f0840.

I also submitted bottom-up versions in Java and C, both accepted. The Java one ran on SPOJ in 1.05s (barely missing the cutoff), and the C version ran in 0.07s. The Java code runs in less than 10ms from start to end of main() on my laptop.

There should be some compensation for slower compiler and runtime startup.

Please update the languages for this problem to exclude Scala.

(Sorry for the multiple posts!)

Last edit: 2015-07-26 06:06:34
sourcedelica: 2015-07-25 22:50:21

I wrote a bottom up version too, both versions execute (after startup) in less than 20ms with an input of 10,000 monsters on my laptop, but get TLE here.

Last edit: 2015-07-26 00:59:22
sourcedelica: 2015-07-25 20:59:04

Anyone get it to work with a memoized recursive solution on JVM using Java or Scala? Mine is running in O(N) but I'm always getting TLE.

xcmn: 2015-07-25 11:50:17

There actually is a space after ':' not giving a space after it gave me a WA.

Krzysztof Strojny: 2015-07-22 11:33:20

Simple DP in 20 minuts, look for input size, int is to small for edge case.

anuveshkothari: 2015-07-18 12:52:36

my first dynamic problem.....finally solved...

shravinson: 2015-07-17 11:58:51

my 50th problem got AC

Vaporeon: 2015-07-17 08:19:16

A space after ' : ' in output cost me 5 WA's. -___________________- .
O(n) dp! :D
NB: Array size is GREATER than 10^4. :3

BadeMeow: 2015-07-14 12:03:43

Take care of n = 0


Added by:hossamyosef
Date:2013-05-13
Time limit:1.237s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:FCIS/ASU Local Contest 2013