跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1628. Arthur and Table

  • ID: 1634
  • 传统题
  • 2000ms
  • 256MiB
  • 尝试: 0
  • AC · 已通过: 0
  • 教学难度:提高
  • 上传者:
  • 枚举
  • 数据结构
  • 动态规划
  • 贪心
  • 数学
  • 排序
  • 算法思想
  • 编程与模拟
  • 提高
  • 难度
  • 共享题库
  • Codeforces
  • 英文题面
  • 题目来源
  • 题面语言

Arthur and Table

题目描述

C. Arthur and Table
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 li.

Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di−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.

Input

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 li (1≤li≤105), where li 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 di (1≤di≤200), where di is the number of energy units that Arthur spends on removing the i-th leg off the table.

Output

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

Examples
Input
2
1 5
3 2
Output
2
Input
3
2 4 4
1 1 1
Output
0
Input
6
2 2 1 1 3 3
4 3 5 5 2 1
Output
8

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1153 题。保留原作者与原赛事署名。