CF802C.Heidi and Library (hard)

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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 ii is cic_{i} CHF.

输入格式

The first line of input will contain two integers nn and kk (). The second line will contain nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=n1<=a_{i}<=n ) – the sequence of book requests. The third line contains nn integers c1,c2,...,cnc_{1},c_{2},...,c_{n} ( 0<=ci<=1060<=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 33 , Heidi should discard either book 11 or 22 . Even though book 22 will be requested later than book 11 , she should keep it, because it is so expensive to buy again.

首页