Heidi and Library (hard)

题意翻译

你有一个容量为 $k$ 的空书架,现在共有 $n$ 个请求,每个请求给定一本书 $a_i$,如果你的书架里没有这本书,你就必须以 $c_{a_i}$ 的价格购买这本书放入书架。当然,你可以在任何时候丢掉书架里的某本书。请求出完成这 $n$ 个请求所需要的最少价钱。 $n, k \leq 80$,$c_i \leq 10^6$。

题目描述

The good times at Heidi's library are over. Marmots finally got their internet connections and stopped coming to the library altogether. Not only that, but the bookstore has begun charging extortionate prices for some books. Namely, whereas in the previous versions each book could be bought for 1 CHF, now the price of book $ i $ is $ c_{i} $ CHF.

输入输出格式

输入格式


The first line of input will contain two integers $ n $ and $ k $ (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF802C/cd9a756e76dcec01df6123e4dbcac76637b09003.png)). The second line will contain $ n $ integers $ a_{1},a_{2},...,a_{n} $ ( $ 1<=a_{i}<=n $ ) – the sequence of book requests. The third line contains $ n $ integers $ c_{1},c_{2},...,c_{n} $ ( $ 0<=c_{i}<=10^{6} $ ) – the costs of the books.

输出格式


On a single line print the minimum cost of buying books at the store so as to satisfy all requests.

输入输出样例

输入样例 #1

4 80
1 2 2 1
1 1 1 1

输出样例 #1

2

输入样例 #2

4 1
1 2 2 1
1 1 1 1

输出样例 #2

3

输入样例 #3

4 2
1 2 3 1
1 1 1 1

输出样例 #3

3

输入样例 #4

7 2
1 2 3 1 1 1 2
1 10 1 0 0 0 0

输出样例 #4

13

说明

The first three sample cases are repeated, but the fourth one is new. In the fourth test case, when buying book $ 3 $ , Heidi should discard either book $ 1 $ or $ 2 $ . Even though book $ 2 $ will be requested later than book $ 1 $ , she should keep it, because it is so expensive to buy again.