Coffee Breaks

All submissions for this problem are available.
Read problems statements in Mandarin Chinese , Russian and Vietnamese
Sergey works as a programmer. Like all programmers, he is a coffee fan. He likes coffee so much that has K cups of coffee daily. However, having more than K cups doesn't suit him, because the excess caffeine won't allow him to sleep at night.
Sergey's working day is divided into N periods. For every period, he knows how many kilobytes of code he can produce.
During each of the periods, Sergey can either have or not to have one cup of coffee. If he is having a cup of coffee in some period, the amount of code he writes in this period drops to zero. But he also gets a productivity boost — if he decides to skip coffee during a period and the last cup of coffee he had was no more than D periods ago, the amount of code he writes during such a period is M times the usual.
As his productivity advisor (congrats on your new job!), help Sergey plan his coffee breaks optimally. Please find the maximum number of lines of code he can write, provided that he has exactly K coffee breaks during the day.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains four space separated integers N, K, D and M denoting the number of the working periods, the number of coffeebreaks and two more parameters as described in the statement.
The second line contains N spaceseparated integers A_{1}, A_{2}, ... , A_{N} denoting the number of kilobytes of code that Sergey writes during each period.
Output
For each test case, output a single line containing the maximum number of kilobytes of code that Sergey can produce if he takes exactly K coffee breaks.
Constraints
 1 ≤ T ≤ 200
 In subtasks 13 it holds that 1 ≤ sum of all N over the test case ≤ 1000
 Subtask 1 (15 points): K = 1, 1 ≤ D < N ≤ 18
 Subtask 2 (25 points): 1 ≤ K, D < N ≤ 18
 Subtask 3 (30 points): 1 ≤ K, D < N ≤ 200
 Subtask 4 (30 points): 1 ≤ K, D < N ≤ 5000, 1 ≤ sum of all N over the test case ≤ 5000
 1 ≤ M, A_{i} ≤ 1000
Example
Input: 1 5 2 2 10 1 2 3 4 5 Output: 110
Explanation
Example case 1. Sergey will have coffee during the periods numbered 1 and 3. In these periods, the amount of code he produces will be zero, but during the rest, his code production quantities will get multiplied by 10. Thus, we will write (2 + 4 + 5) * 10 KB of code.
Author:  xcwgf666 
Tester:  logic_iu 
Editorial  http://discuss.codechef.com/problems/COFFEE 
Tags  dynamicprogramming, ltime28, medium, xcwgf666 
Date Added:  23082015 
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 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions