CF1082F.Speed Dial

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp's phone book contains nn phone numbers, each of them is described by sis_i — the number itself and mim_i — the number of times Polycarp dials it in daily.

Polycarp has just bought a brand new phone with an amazing speed dial feature! More precisely, kk buttons on it can have a number assigned to it (not necessary from the phone book). To enter some number Polycarp can press one of these kk buttons and then finish the number using usual digit buttons (entering a number with only digit buttons is also possible).

Speed dial button can only be used when no digits are entered. No button can have its number reassigned.

What is the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way?

波利卡普的电话簿中包含 nn 个电话号码,每个号码由 sis_i(号码本身)和 mim_i(波利卡普每天拨打该号码的次数)描述。

波利卡普刚刚购买了一部全新手机,该手机具备一项令人惊叹的快速拨号功能!具体而言,手机上有 kk 个按键可以被分配一个号码(该号码不一定要来自电话簿)。要输入某个号码,波利卡普可以先按这 kk 个按键中的某一个,然后使用普通数字键完成剩余部分(当然,也可以完全不使用快速拨号键,而仅用数字键输入整个号码)。

快速拨号键只能在尚未输入任何数字时使用。任意按键一旦分配了号码,便不可重新分配。

在为快速拨号键分配号码,并以最优方式对电话簿中的每个号码各拨打 mim_i 次的前提下,波利卡普所能达到的数字键总按压次数的最小值是多少?

输入格式

The first line contains two integers nn and kk (1≤n≤5001 \le n \le 500, 1≤k≤101 \le k \le 10) — the amount of numbers in Polycarp's phone book and the number of speed dial buttons his new phone has.

The ii-th of the next nn lines contain a string sis_i and an integer mim_i (1≤mi≤500)(1 \le m_i \le 500), where sis_i is a non-empty string of digits from 00 to 99 inclusive (the ii-th number), and mim_i is the amount of times it will be dialed, respectively.

It is guaranteed that the total length of all phone numbers will not exceed 500500.

第一行包含两个整数 nn 和 kk(1≤n≤5001 \le n \le 500,1≤k≤101 \le k \le 10)—— 分别表示 Polycarp 电话簿中的号码数量以及他新手机上速拨按钮的数量。

接下来的 nn 行中,第 ii 行包含一个字符串 sis_i 和一个整数 mim_i(1≤mi≤5001 \le m_i \le 500),其中 sis_i 是一个非空字符串,仅由数字 00 到 99 组成(即第 ii 个电话号码),而 mim_i 表示该号码将被拨打的次数。

保证所有电话号码的总长度不超过 500500。

输出格式

Print a single integer — the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way.

输出一个整数——即 Polycarp 在为快捷拨号按钮分配号码,并以最优方式依次拨打电话簿中的每个号码(按给定次数)后,所能达到的数字按键总次数的最小值。

输入输出样例

  • 输入#1

    3 1
    0001 5
    001 4
    01 1

    输出#1

    14
  • 输入#2

    3 1
    0001 5
    001 6
    01 1

    输出#2

    18

说明/提示

The only speed dial button in the first example should have "0001" on it. The total number of digit button presses will be 0⋅50 \cdot 5 for the first number + 3⋅43 \cdot 4 for the second + 2⋅12 \cdot 1 for the third. 1414 in total.

The only speed dial button in the second example should have "00" on it. The total number of digit button presses will be 2⋅52 \cdot 5 for the first number + 1⋅61 \cdot 6 for the second + 2⋅12 \cdot 1 for the third. 1818 in total.

第一个示例中唯一的快速拨号按钮上应显示“0001”。数字按键的总按压次数为:第一个号码 0⋅50 \cdot 5 次 + 第二个号码 3⋅43 \cdot 4 次 + 第三个号码 2⋅12 \cdot 1 次,总计 1414 次。

第二个示例中唯一的快速拨号按钮上应显示“00”。数字按键的总按压次数为:第一个号码 2⋅52 \cdot 5 次 + 第二个号码 1⋅61 \cdot 6 次 + 第三个号码 2⋅12 \cdot 1 次,总计 1818 次。

输入解题思路,AI测评打分。不知道怎么写?

首页