CF748D.Santa Claus and a Palindrome

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The first line contains two positive integers kk and nn divided by space and denoting the number of Santa friends and the length of every string they've presented, respectively ( 1<=k,n<=1000001<=k,n<=100000 ; nk <=100000n·k <=100000 ).

kk lines follow. The ii -th of them contains the string sis_{i} and its beauty aia_{i} ( 10000<=ai<=10000-10000<=a_{i}<=10000 ). The string consists of nn lowercase English letters, and its beauty is integer. Some of strings may coincide. Also, equal strings can have different beauties.

输入格式

In the only line print the required maximum possible beauty.

输出格式

In the first example Santa can obtain abbaaaxyxaaabba by concatenating strings 55 , 22 , 77 , 66 and 33 (in this order).

输入输出样例

  • 输入#1

    7 3
    abb 2
    aaa -3
    bba -1
    zyz -4
    abb 5
    aaa 7
    xyx 4
    

    输出#1

    12
    
  • 输入#2

    3 1
    a 1
    a 2
    a 3
    

    输出#2

    6
    
  • 输入#3

    2 5
    abcde 10000
    abcde 10000
    

    输出#3

    0
    

说明/提示

In the first example Santa can obtain abbaaaxyxaaabba by concatenating strings 55 , 22 , 77 , 66 and 33 (in this order).

首页