Anda di halaman 1dari 2

9/5/2014

User:
Password:

for today

Log In

register
tutorials
status
submit
problems
search
ideone.com

SPOJ.com - Problem DCEPC501

Submit

All submissions

Best solutions

PS

SPOJ Problem Set (classical)

Lubi to!

11404. Save Thy Toys

Udostpnij

PDF

Back to list

Problem code: DCEPC501

Free REST API Platform


dreamfactory.com
Install open source on any server Connect to SQL or NoSQL data

news
contests
ranks

Leonard is very fond of buying rare and expensive science fiction toys. He keeps his collection in a sequential
order of the date on which the toy was bought in a special closet so that his roomie Sheldon never gets hold
of his toys. But because of his bad luck Leonard once loses a bet to Sheldon and Sheldon demands a share
Leonards toys. Since Leonard doesnt want to loose much money, he decides upon a strategy to reduce his
loss to minimum.

forum
tools
clusters
credits
jobs

Leonard, beginning from the first toy in his closet will pick some toys, say "x" toys in sequence. Sheldon will
then pick the next "x" toys (Note that Sheldon picks equal no. of toys as picked by Leonard in his move unless
the remaining toys are less than "x". In that case he picks all of the remaining). This will keep going on till no
more toys are left in the closet for Leonard to pick. You are given the sequence of toys with their price. Help
Leonard in maximizing the total price of all toys he picks.

Se rve r tim e :
2014-09-05
15 : 51 : 53

Leonard in his each turn can either pick only 1 or 2 or 3 toys ("x" described above can take value either 1, 2
or 3).

Input
First line specifies T, the number of test cases.
Each test case contains N in the first line. Second line contains N integers as described above.

Output
Output 1 line for each test case giving the maximum possible value of the total sum of all toys Leonard picks.

Constraints
1<=T<=10
1<=N<=100000
1<=Price of toys<=1000000

Example
Input:Time for a new job?
2
4
5432
6
10 8 7 11 15 20
Output:
12
53

Explanation:
In 1st case, Leonard picks 3 toys in his first move with value 5,4,3 and Sheldon has no choice but to pick the
last.
In 2nd case, Leonard picks 10, 8. Then Sheldon picks 7,11. And then Leonard picks the rest.
Added by:
Date:
Time limit:
Source limit:
Memory limit:
Cluster:
Languages:
Resource:

dce coders
2012-04-18
3s
50000B
256MB
Pyramid (Intel Pentium III 733 MHz)
C C++ 4.3.2 C++ 4.0.0-8 JAVA NODEJS PYTH 3.2.3 n
Own Problem
hide comments

Previous

Next >

2014-08-19 13:50:17 Ravi kumar

http://www.spoj.com/problems/DCEPC501/

1/2

9/5/2014

SPOJ.com - Problem DCEPC501


DP :D
2014-06-24 17:32:17 beginner
any tricky test case?
i m getting wa
2014-06-24 15:43:33 Hariharan
ad-hoc solution WA.
2014-01-15 10:19:10 parbays
looks simple prob with straightforward dp states. This O(n) submission was 4.6s and AC, despite the time
limit of 3s. I dont understand.
2013-12-24 19:10:58 Python
Good problem :D
2013-12-18 18:39:32 SanchitK
does Lenord gets to change the number of toys he pics in each turn,or is the x constant for a given test
case,
say can he pick 1,2,2 in his turns,or he has to pick 2,2,2 only(if possible)
@dce coders pls give more test cases
Last edit: 2013-12-18 18:41:37
2013-12-17 22:22:43 Sameer
@Kevin Sebastian--> YES
2013-10-17 19:12:42 Simes
Can Free Pascal be allowed please?
2013-09-11 22:25:47 Siddharth Agarwal
after wasting 4 hrs in solving TLE, used scanf instead of cin and got ac .
2013-08-26 09:25:34 Kevin Sebastian
this can be solved in O(N) TIME RIGHT?

About SPOJ

width: 900 1024 Full

theme: olive banana plum hspl

#spoj at freenode

RSS

Spoj.com . All R ights R e se rve d. Spoj use s Sphe re Engine by Sphe re R e se arch Labs.

http://www.spoj.com/problems/DCEPC501/

2/2

Anda mungkin juga menyukai