Problem C
Magic Show
Languages
en
sv
Mårten the Magician is currently performing in a magnificent
magic competition. The show consists of
For each rabbit Mårten makes appear or disappear, he must
use 1 magick. In the beginning of the show, Mårten has
The scoring of the competition is easy. In the
In round
Mårten’s total score in the competition is the sum of scores among all the rounds. What is the maximum score Mårten can get if he performs optimally?
Example
Consider a competition with
The optimal play from Mårten is then to do nothing in the
first round (
This totals
Task
Given all the rounds of the competition, you are to determine the maximum score Mårten can get, and construct instructions for him.
You should implement the function magic_score(N, K, L, R).
-
magic_score(N, K, L, R) - this function will be called exactly once by the judge.
-
N: the number of rounds in the competition.
-
K: the amount of magicks Mårten has in the beginning of the show.
-
L: an array with
elements, containing the values L[i] as descriped in the task. -
R: an array with
elements, containing the values R[i] as descriped in the task. -
-
is even -
The function should return the maximum score Mårten can obtain.
-
Additionally, you should call the function trick(X) to tell Mårten what he should do in each round.
-
trick(X) - this function should be called by your program once for every round. The
:th call should give the instruction to Mårten in the :th round if Mårten wants to play optimally.-
X: this parameter should give the value
of each of Mårten’s rounds. If Mårten should add rabbits, this value should be the number of rabbits Mårten should add. If he should remove rabbits, it should be the negative value of the number of rabbits he removes. If he should not do any trick in the round, the value should be . -
The function has no return value.
-
A code skeleton containing the function to be implemented, together with a sample grader, can be found at http://progolymp.se/uploads/kattis-attachments/magic.zip.
Subtasks
The problem consists of a number of subtasks. Each subtask gives some amount of points, and to pass the subtask you must pass all the test cases in the subtask.
For each subtask, if the return value of magic_score(N, K, L, R) is correct, but your
calls to trick(X) is not a valid
sequence giving the maximum score, you will get
Subtask |
Points |
Limits |
1 |
20 |
|
2 |
20 |
|
3 |
20 |
|
4 |
40 |
|
Input format
The sample judge reads input in the following format:
-
line
: N K -
line
: L[0] L[1] .. L[N - 1] -
line
: R[0] R[1] .. R[N - 1]
Output format
The sample judge writes output in the following format:
-
line
: the return value of magic_score(N, K, L, R) on a line -
line
: integers, the values given from the calls to trick(X) in order.
Sample Input 1 | Sample Output 1 |
---|---|
4 5 3 -2 -2 2 5 2 0 6 |
5 0 2 0 2 |