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

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

hide comments
2024-08-08 15:46:44
why gives me runtime ?
<snip>
[Simes]: what happens with these lines when n = 0?
v.resize(n);
cout << "Case " << count++ << ": " << dp[n - 1] << endl;

Last edit: 2024-08-08 20:46:34
2023-07-06 16:23:30
Any reason that ASM64 isn't accepted for this?
2023-04-21 12:26:16
Test case:
9
5
1 1 1 1 1
0
2
12 15
2
15 12
5
10 1 1 1 1
3
12 3 1
3
2 2 2
2
5 2
4
10 5 2 1000

Output:
Case 1: 3
Case 2: 0
Case 3: 15
Case 4: 15
Case 5: 12
Case 6: 13
Case 7: 4
Case 8: 5
Case 9: 1010
2023-03-16 19:21:58
stupid n=0 test case.
2022-03-04 01:34:54
First try :)))))))))
2021-12-24 11:32:05
Can someone please explain why I am getting an NZEC error for the correct python solution? This s**t platform discourages every other language except C++!

[NG]: Correct Python solutions get AC:
https://www.spoj.com/ranks/FARIDA/lang=PYTH%202.7
Blame the player not the game.

[RE]: I'm sorry, but this doesn't explain the reason for NZEC error. My solution is correct (checked with multiple sources + rechecked with solutions on YT).

[NG]: In my experience, two most frequent reasons for NZEC in a seemingly "correct" Py code are:
- not handling of formatting errors in testfiles (not the case here)
- stack overflow (typically with recursion; can be circumvented with sys.setrecursionlimit() but best avoided when possible).
Hope that helps.

[RE]: I don't use recursion in my approach, so the error must pretty much occur in the input stage. Problem is, the correct parameters are not described in the question properly. I've tried all the possible cases, even using an EOFError exception for n == 0. Frustrating, to say the least.

Last edit: 2021-12-28 06:15:09
2021-10-10 08:09:59
use long long instead of int
2021-09-26 18:09:08
Wasted terrible time on this case -> n == 0
Do consider this while writing any solution
2021-08-30 21:49:57
Exactly same as : https://leetcode.com/problems/house-robber/
2021-07-12 20:05:27
stupid n == 0 case.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.