Magic Show | 프로그래밍의 벗 PivotOJ
PivotOJ

Magic Show

시간 제한: 1000ms메모리 제한: 1024MB출처: Programmeringsolympiaden 2016 — katt1BOJ 21332

문제

Mårten the Magician is currently performing in a magnificent magic competition. The show consists of NN rounds. In each round, Mårten uses his magic to perform one of two tricks: either he makes some number xx rabbits appear, or he sabotages his opponents' tricks by making some number yy of their rabbits disappear. He can also choose to do neither.

For each rabbit Mårten makes appear or disappear, he must use 1 magick. In the beginning of the show, Mårten has KK magicks. When he has run out of magicks, he can no longer perform a trick.

The scoring of the competition is easy. In the ii:th round, let \[ S_i = \begin{cases} x & \text{ if Mårten made xx rabbits appear } \\ -y & \text{ if Mårten made yy rabbits disappear } \\ 0 & \text{ if Mårten didn't perform a trick} \end{cases} \]

In round ii, if SiS_i is in the interval [L[i],R[i]][L[i], R[i]] where L[i]L[i] and R[i]R[i] are integers specific to the round, he gets SiL[i]+R[i]2|S_i - \frac{L[i] + R[i]}{2}| points. If SiS_i is outside this interval, Mårten gets 00 points. Note that Mårten cannot perform his magic on fractional rabbits, thus SiS_i will always be an integer.

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?

입력

The sample judge reads input in the following format:

  • line 11: N K
  • line 22: L[0] L[1] .. L[N - 1]
  • line 33: R[0] R[1] .. R[N - 1]

출력

The sample judge writes output in the following format:

  • line 11: the return value of magic_score(N, K, L, R) on a line
  • line 22: NN integers, the values given from the calls to trick(X) in order.

예제

예제 1

입력
4 5
3 -2 -2 2
5 2 0 6
출력
5
0 2 0 2
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.