题库练习 Heidi and Library (hard)
← 上一题 下一题 →

A10893 | Heidi and Library (hard)

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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$ (![](/uploads/acgo/image/348237a64d090605_f01e784fe33c.jpeg)). 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
C++ 编辑器
输入
输出