C. Arthur and Table
time limit per test
memory limit per test
input
output
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
n legs, the length of the i-th leg is li.
di — the amount of energy that he spends to remove the i-th leg.
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 5legs 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
n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.
n integers li (1 ≤ li ≤ 105), where li is equal to the length of the i-th leg of the table.
n integers di (1 ≤ di), 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.
Sample test(s)
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
题意:
给你一张桌子,有n条腿,告诉每条腿的长度(l)以及砍掉这条腿的花费(d),当最长腿的数量超过总数量的1/2,那么合法。问如何使得花费最小达到合法情况。
解法:
分别枚举以当前长度为最长的长度,砍去所有长度大于它的。删去长度小于它且花费最少的。
代码: