QOJ.ac

QOJ

حد الوقت: 4 s حد الذاكرة: 512 MB مجموع النقاط: 100

#8628. Maximum Subarray Sum

الإحصائيات

Given a sequence $a_1, a_2, ..., a_N$ of length $N$ and a sequence $b_1, b_2, ..., b_M$ of length $M$. You need to construct an integer sequence $c_1, c_2, ..., c_M$ of length $M$ such that:

  • $0 \le c_i \le N$.
  • Each non-zero element appears at most once in $c$.

After constructing the sequence $c$, you perform the following operations in order:

  • If $c_i \neq 0$, replace $a_{c_i}$ with $b_i$.

Find the maximum possible value of the maximum contiguous subarray sum ($\max\limits_{1 \le l \le r \le N} (\sum_{i = l}^{r} a_i)$) of the sequence $a$ after the replacements.

Input

The first line contains two integers $N$ and $M$, representing the lengths of sequence $a$ and sequence $b$.

The next line contains $N$ integers $a_1, a_2, ..., a_N$.

The next line contains $M$ integers $b_1, b_2, ..., b_M$.

Output

Output a single integer representing the maximum possible contiguous subarray sum of sequence $a$ after the replacements.

Examples

Input 1

3 1
3 -6 3
-2

Output 1

4

Note 1

Let $c_1=2$. During the operation, $a_{c_1}(a_2)$ is replaced by $-2$.

$\max\limits_{1 \le l \le r \le N} (\sum_{i = 1}^{3} a_i) = 3 + (-2) + 3 = 4$.

Constraints

  • $1 \le N \le 10^5$
  • $0 \le M \le 10^5$
  • $-10^9 \le a_i, b_i \le 10^9$

20% of the score satisfies $N, M \le 500$.

Another 30% of the score satisfies $N, M \le 2000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.