問題一覧 > 通常問題

No.3684 chokudai_niku.png

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 144
作問者 : triangle_coder / テスター : ゆにたりー卿 drken1215 Mikan04y lp_ql yimiya(いみや) よには 👑 loop0919 elphe Andrew8128 edon8618 👑 seekworser leaf_1415 紫前燈太 👑 みうね
お気に入りにしたユーザー ProblemId : 13546 / 自分の提出
問題文最終更新日: 2026-09-05 01:14:12
chokudai_niku.png
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
第3回 岩井星人アンソロジープログラミングコンテスト (順位表) の他の問題:

Problem Statement

Iwai Seijin had secured a promise that Takahashi-kun would treat him to yakiniku, and had saved an image file, chokudai_niku.png, as proof.

chokudai_niku.png

However, Iwai Seijin schemed to get taken to an expensive restaurant by tampering with this image.

chokudai_niku.png (after tampering)

In this way, Iwai Seijin sometimes tampers with the contents of promises to suit himself.

Takahashi-kun is going to treat Iwai Seijin to yakiniku for $M$ consecutive days within the upcoming $N$ days.

For each $i\ (1 \leq i \leq N)$, at the restaurant Iwai Seijin can be taken to on day $i$, he will be treated to $A_i$ yen worth of yakiniku, and the transportation cost he must pay to get to the restaurant is ${B_i}$ yen.

Iwai Seijin can freely choose the first day on which he is treated to yakiniku.
That is, he can choose an integer $s$ in the range $1 \leq s \leq N-M+1$ and be treated to yakiniku from day $s$ through day $s+M-1$.

Furthermore, by tampering with the list of scheduled yakiniku days, Iwai Seijin can choose any number of days he likes and skip them. He may skip all of the days.

Iwai Seijin feels he has gained an amount equal to the total price of the yakiniku he was treated to minus the total transportation cost.
Find the maximum possible amount that Iwai Seijin can feel he has gained.

Constraints

  • $1 \le N \le 2×10^5$
  • $1 \le M \le N$
  • $0 \le A_i,\ B_i \le 10^9$
  • All inputs are integers.

Input

The input is given from standard input in the following format.

$N$ $M$
$A_1$ $A_2$ ... $A_N$
$B_1$ $B_2$ ... $B_N$

Output

Output the maximum possible amount that Iwai Seijin can feel he has gained.

Sample

Sample 1
Input
5 3
600 800 600 600 900
500 700 300 200 400
Output
1200

If Iwai Seijin is treated from day $3$ through day $5$, he feels he has gained $300+400+500$ yen, which is the maximum.

Sample 2
Input
6 4
300 500 3000 0 2000 4000
100 600 2000 100000 0 1000
Output
6000

By choosing the interval from day $3$ through day $6$ and being treated to yakiniku on days $3,\ 5,\ 6$, Iwai Seijin feels he has gained $1000+2000+3000=6000$ yen, which is the maximum.

Sample 3
Input
4 2
0 0 0 0
1 2 3 4
Output
0

There are cases where Iwai Seijin cannot feel he has gained anything.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。