CF1425E.Excitation of Atoms

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it.

There are NN atoms numbered from 11 to NN. These atoms are especially quirky. Initially, each atom is in normal state. Each atom can be in an excited. Exciting atom ii requires DiD_i energy. When atom ii is excited, it will give AiA_i energy. You can excite any number of atoms (including zero).

These atoms also form a peculiar one-way bond. For each ii, (1≤i<N)(1 \le i \lt N), if atom ii is excited, atom EiE_i will also be excited at no cost. Initially, EiE_i = i+1i+1. Note that atom NN cannot form a bond to any atom.

Mr. Chanek must change exactly KK bonds. Exactly KK times, Mr. Chanek chooses an atom ii, (1≤i<N)(1 \le i \lt N) and changes EiE_i to a different value other than ii and the current EiE_i. Note that an atom's bond can remain unchanged or changed more than once. Help Mr. Chanek determine the maximum energy that he can achieve!

note: You must first change exactly KK bonds before you can start exciting atoms.

陈克先生目前正在参加一场镇上颇受欢迎的科学博览会。他在博览会上发现了一个有趣的谜题,想要解开它。

共有 NN 个原子,编号从 11 到 NN。这些原子行为十分奇特:初始时,每个原子均处于正常状态;每个原子均可被激发为激发态。激发原子 ii 需要消耗 DiD_i 能量,而一旦原子 ii 被激发,它将释放 AiA_i 能量。你可以选择激发任意数量的原子(包括零个)。

此外,这些原子之间还形成一种特殊的单向键。对每个 ii(其中 1≤i<N1 \le i < N),若原子 ii 被激发,则原子 EiE_i 也将被免费激发(即无需额外能量)。初始时,Ei=i+1E_i = i+1。注意:原子 NN 无法与任何其他原子形成键。

陈克先生必须恰好修改 KK 条键。具体而言,他需恰好执行 KK 次操作:每次选择一个原子 ii(其中 1≤i<N1 \le i < N),并将 EiE_i 修改为一个不同于 ii 且不同于当前 EiE_i 的新值。注意:某原子的键可以保持不变,也可以被多次修改。请帮助陈克先生计算他所能获得的最大能量!

注意:你必须先恰好完成 KK 次键的修改,然后才能开始激发原子。

输入格式

The first line contains two integers NN KK (4≤N≤105,0≤K<N)(4 \le N \le 10^5, 0 \le K \lt N), the number of atoms, and the number of bonds that must be changed.

The second line contains NN integers AiA_i (1≤Ai≤106)(1 \le A_i \le 10^6), which denotes the energy given by atom ii when on excited state.

The third line contains NN integers DiD_i (1≤Di≤106)(1 \le D_i \le 10^6), which denotes the energy needed to excite atom ii.

第一行包含两个整数 NN 和 KK (4≤N≤105,0≤K<N)(4 \le N \le 10^5, 0 \le K \lt N),分别表示原子的数量以及必须更改的化学键数量。

第二行包含 NN 个整数 AiA_i (1≤Ai≤106)(1 \le A_i \le 10^6),表示第 ii 个原子处于激发态时所释放的能量。

第三行包含 NN 个整数 DiD_i (1≤Di≤106)(1 \le D_i \le 10^6),表示将第 ii 个原子激发所需的能量。

输出格式

A line with an integer that denotes the maximum number of energy that Mr. Chanek can get.

一个整数,表示陈先生能获得的最大能量值。

输入输出样例

  • 输入#1

    6 1
    5 6 7 8 10 2
    3 5 6 7 1 10

    输出#1

    35

说明/提示

An optimal solution to change E5E_5 to 1 and then excite atom 5 with energy 1. It will cause atoms 1, 2, 3, 4, 5 be excited. The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10) - 1 = 35.

Another possible way is to change E3E_3 to 1 and then exciting atom 3 (which will excite atom 1, 2, 3) and exciting atom 4 (which will excite atom 4, 5, 6). The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10 + 2) - (6 + 7) = 25 which is not optimal.

将 E5E_5 改为 1,然后用能量 1 激发原子 5。这将导致原子 1、2、3、4、5 均被激发。陈先生获得的总能量为 (5+6+7+8+10)−1=35(5 + 6 + 7 + 8 + 10) - 1 = 35。

另一种可行方案是:将 E3E_3 改为 1,然后激发原子 3(这将激发原子 1、2、3)以及激发原子 4(这将激发原子 4、5、6)。陈先生获得的总能量为 (5+6+7+8+10+2)−(6+7)=25(5 + 6 + 7 + 8 + 10 + 2) - (6 + 7) = 25,该方案并非最优。

输入解题思路,AI测评打分。不知道怎么写?

首页