#P16430. 危机重重

    ID: 18389 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>贪心高精度O2优化枚举排序

危机重重

Background

Algo Beat has run into a series of crises. They plan to send several people to resolve the crises in order to ensure national security.

Problem Description

There are nn people as candidates to resolve the crisis. However, they will only work seriously if, among the people sent, everyone has the same diligence value pip_i. You may also perform any number of upgrade operations (possibly 00 times):

  • Choose an i (1in)i\ (1 \le i \le n), and spend wiw_i dollars to increase pip_i by 11.

The king wants to select kk people to send, but he wants to minimize the total cost, so he asks you, who can program, to help him.

Input Format

The first line contains two integers nn and kk.

The second line contains nn integers pip_i, representing the initial diligence values.

The third line contains nn integers wiw_i, representing the cost required for an upgrade.

Output Format

Output one integer in a single line, representing the minimum cost.

5 4
1 2 1 2 1
6 3 4 5 4
8

Hint

Subtask #0 is the sample and is worth 00 points.

Constraints

This problem uses bundled testdata.

For all testdata, it holds that:

  • 1n10001 \le n \le 1000, 1kn1 \le k \le n, 1pi1091 \le p_i \le 10^9, 1wi1091 \le w_i \le 10^9.

::cute-table{tuack}

Subtask ID kk Special Property Score
11 =1=1 None 1010
22 =2=2 2020
33 n\leq n A 1010
44 B
55 None 5050
  • Special Property A: It is guaranteed that w1=w2==wnw_1 = w_2 = \dots = w_n.
  • Special Property B: It is guaranteed that pp is a permutation of 1n1 \sim n.

Translated by ChatGPT 5