QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 512 MB Total points: 100

#8628. 最大连续和

الإحصائيات

题目描述

给定长度为$N$的序列$a_1, a_2, ..., a_N$,和长度为$M$的序列$b_1, b_2, ..., b_M$。 接着你需要构造出一个长度为$M$的整数序列$c_1, c_2, ..., c_M$,满足:

  • $0 \le c_n \le N$。
  • 每个非$0$元素在$c$中出现次数不能超过$1$次。

构造完序列$c$后,你将依序做以下的操作:

  • 若$c_i\neq 0$ ,将$a_{c_i}$替换成$b_i$。

试求在经由你构造的序列c替换完以后,序列$a$的最大连续和($\max\limits_{1 \le l \le r \le N} (\sum_{i = l}^{r} a_i)$)能多大。

输入格式

输入的第一行包含两个整数$N$和$M$,代表序列$a$和序列$b$的长度。

接下来的一行包含$N$整数$a_1, a_2, ..., a_N$。

接下来的一行包含$M$整数$b_1, b_2, ..., b_M$。

输出格式

输出一行一个整数表示经由你构造的序列c替换完以后,序列$a$的最大连续和能多大。

样例

输入

3 1
3 -6 3
-2

输出

4

解释

令 $c_1=2$ ,操作时 $a_{c_1}(a_2)$ 被替换为 $-2$ 。

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

子任务

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

前20%的分数满足 $N, M \le 500$。

其余有30%的分数满足 $N, M \le 2000$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.