CF557C.Arthur and Table

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.

In total the table Arthur bought has n legs, the length of the i-th leg is l__i.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number d__i — the amount of energy that he spends to remove the i-th leg.

A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.

Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.

阿瑟买了一张漂亮的大桌子放到他的新公寓里。回家后,阿瑟发现这张新桌子不稳定。

这张桌子总共有 nn 条腿,第 ii 条腿的长度为 lil_i。

阿瑟决定通过移除一些桌腿来使桌子变得稳定。对于每条腿 ii,他确定了移除它所需的能量值 did_i。

一张有 kk 条腿的桌子被认为是稳定的,当且仅当其中长度等于最大腿长的腿的数量超过一半。例如,要使一张有 5 条腿的桌子稳定,必须确保这 5 条腿中至少有 3 条腿的长度等于当前所有剩余腿中的最大长度。此外,只有一条腿的桌子总是稳定的;而有两条腿的桌子稳定当且仅当这两条腿长度相等。

你的任务是帮助阿瑟计算:为使桌子稳定,他所需花费的最小能量单位总数是多少?

输入格式

The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.

The second line of the input contains a sequence of n integers l__i (1 ≤ l__i ≤ 105), where l__i is equal to the length of the i-th leg of the table.

The third line of the input contains a sequence of n integers d__i (1 ≤ d__i ≤ 200), where d__i is the number of energy units that Arthur spends on removing the i-th leg off the table.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 1051 \leq n \leq 10^5)—— 表示亚瑟所购桌子初始的腿的数量。

输入的第二行包含一个由 nn 个整数 lil_i(1 ≤ li ≤ 1051 \leq l_i \leq 10^5)组成的序列,其中 lil_i 表示桌子第 ii 条腿的长度。

输入的第三行包含一个由 nn 个整数 did_i(1 ≤ di ≤ 2001 \leq d_i \leq 200)组成的序列,其中 did_i 表示亚瑟移除桌子第 ii 条腿所需消耗的能量单位数。

输出格式

Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.

输出一个整数——Arthur 为使桌子稳定所需消耗的最少能量单位数。

输入输出样例

  • 输入#1

    2
    1 5
    3 2

    输出#1

    2
  • 输入#2

    3
    2 4 4
    1 1 1

    输出#2

    0
  • 输入#3

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

    输出#3

    8

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

首页