#PS0000192. Tối đa số định lý ghi chép (Lecture Sleep)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tối đa số định lý ghi chép (Lecture Sleep)
Lecture Sleep
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A lecture lasts minutes. At minute the lecturer presents theorems. Mishka records all of them if (awake), and none if (asleep). You may use a technique exactly once to keep Mishka awake for exactly consecutive minutes starting at , where . Outside this interval the original behavior remains unchanged. Maximize the number of theorems recorded, without double counting.
Input
The first line contains . The second contains integers . The third contains integers .
Output
Print the maximum number of recorded theorems.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Example 1
Input
6 3
1 3 5 2 5 4
1 1 0 1 0 0
Output
16
Explanation
Initially 6 theorems are recorded. Choose minutes 3–5 for 10 extra, giving 16.
Example 2
Input
3 2
4 7 2
1 1 1
Output
13
Explanation
All minutes are already awake, so either window gives 13.