Public Judge

pjudge

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#21885. 【PR #14】狼抓兔子

統計

给定数轴上的若干点 $pos_{1...n}$,有一些狼在这些点上,它们的位置在 $pos_{1...n}$ 的范围内,它们想要捕食一些兔子,但是限于精力,每条狼至多只能捕食一只兔子,由于不能饿死,所以每条狼至少需要捕食一只兔子。

兔子有两个大本营位于 $0$ 和 $L$,大本营里有无限多个兔子。而另有一些落单的兔子,它们的位置也在 $pos_{1...n}$ 的范围内。

一个位置为 $x$ 的狼想要捕食一个位置为 $y$ 的兔子需要花费 $|x-y|$ 的代价,请问最小的总代价为多少。

输入格式

第一行一个正整数 $n$,表示范围中存在兔子跟狼的位置的集合大小。

接下来一行 $n$ 个整数 $a_i$,若 $a_i>0$ 则表示 $pos_i$ 位置上有 $a_i$ 只狼,否则表示 $pos_i$ 位置上有 $-a_i$ 只兔子。

接下来一行 $n+1$ 个整数 $b_{0\sim n}$,表示 $pos_{i+1}-pos_{i}$,其中 $pos_0=0,pos_{n+1}=L$,注意 $b_i$ 有可能为 $0$。

输出格式

输出一个整数表示答案。

样例输入 1

1
-100
1 1

样例输出 1

0

样例输入 2

1
100
1 1

样例输出 2

100

样例 3~4

见附加文件。

数据范围

对于 $100\%$ 的数据,令 $c_i=|a_i|$,则 $1\le n\leq 5\times 10^5,0\leq c_i\leq 10^5,0\leq L\leq 5\times 10^8$。

各测试包的附加限制如下表所示:

子任务编号 得分 限制
1 15 $n,\sum c_i \leq 15$
2 10 $n,\sum c_i\leq 5000$
3 5 $a_i\geq 0$
4 20 $b_i=1$
5 25 $n,\sum c_i\leq 5\times 10^5$
6 5 $n\leq 10^5$
7 20 无限制
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.