Robo And Walls
All submissions for this problem are available.
Robo Beast has just acquired a new functionality. It can now Jump (In 0.3 seconds)! Robo wants to test its jumping and mathematical ability. So, his friend Chaitya Drumpf decided to build walls and teach him a lesson.
Given N walls, Robo has to start with the first wall. He has to then jump from one wall to another and so on. Every wall he stands on (Including the first one) has a score Ai, which Robo has to add. He has to jump from wall to wall until he achieves the maximum score possible. However, there's a catch. Chaitya will allow Robo to jump only a particular number of walls at a time. Robo will be given M numbers, B1, B2, ... BM denoting jump strengths. From any wall, Robo can jump only as far one of these jump strengths allow him to.
Robo still isn't sure of his mathematical skills. Can you help him figure out the maximum sum possible?
- First line contains T. T testcases follow.
- The first line of each testcase contains a single integer N, denoting the number of walls. The next line contains N space seperated integers, denoting the score for standing on each wall
- The next line contains M, denoting the number of jumps available, followed by M space seperated integers on the next line.
Output:For each testcase, output the required answer.
Constraints:1 <= T <= 10
1 <= N <= 104
-109 <= Ai <= 109
1 <= M, Bi <= N-1
1 -2 1 -5 3
1 2 3
Robo will have score of 1 on first wall. It will make a jump of 2 to reach the 3rd wall and attain a score of 2. It will again make a jump of 2 to reach the 5th Wall for a final maximum score of 5.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions