15th ZJP Acm - Pro L. Doki Doki Literature Club

假的心跳社玩一波

Des:
Doki Doki Literature Club! is a visual novel developed by Team Salvato. The protagonist is invited by his childhood friend, Sayori, to join their high school’s literature club. The protagonist then meets the other members of the club: Natsuki, Yuri, and the club president Monika. The protagonist starts to participate in the club’s activities such as writing and sharing poetry, and grows close to the four girls. What a lovely story!

A very important feature of the game is its poetry writing mechanism. The player is given a list of various words to select from that will make up his poem. Each girl in the Literature Club has different word preferences, and will be very happy if the player’s poem is full of her favorite words.

BaoBao is a big fan of the game and likes Sayori the most, so he decides to write a poem to please Sayori. A poem of m m words s1,s2,,sm is nothing more than a sequence of m m strings, and the happiness of Sayori after reading the poem is calculated by the formula.

H=i=1m(mi+1)f(si)
where H H is the happiness and f(si) is Sayori’s preference to the word si s i .
Given a list of n n words and Sayori’s preference to each word, please help BaoBao select m words from the list and finish the poem with these m m words to maximize the happiness of Sayori.

Please note that each word can be used at most once!

Input
There are multiple test cases. The first line of input contains an integer T (about 100), indicating the number of test cases. For each test case:

The first line contains two integers n n and m ( 1mn100 1 ≤ m ≤ n ≤ 100 ), indicating the number of words and the length of the poem.

For the following n n lines, the i-th line contains a string consisting of lowercased English letters wi w i ( 1|wi|15 1 ≤ | w i | ≤ 15 ) and an integer f(wi) f ( w i ) ( 109f(wi)109 − 10 9 ≤ f ( w i ) ≤ 10 9 ), indicating the i i -th word and Sayori’s preference to this word. It’s guaranteed that wiwj for all ij i ≠ j .

Output
For each test case output one line containing an integer H H and m strings s1,s2,,sm s 1 , s 2 , … , s m separated by one space, indicating the maximum possible happiness and the corresponding poem. If there are multiple poems which can achieve the maximum happiness, print the lexicographically smallest one.

Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!

A sequence of m m strings a1,a2,,am is lexicographically smaller than another sequence of m m strings b1,b2,,bm, if there exists a k k (1km) such that ai=bi a i = b i for all 1i<k 1 ≤ i < k and ak a k is lexicographically smaller than bk b k .

A string s1=a1a2ax s 1 = a 1 a 2 … a x is lexicographically smaller than another string s2=b1b2by s 2 = b 1 b 2 … b y , if there exists a k k (1kmin(x,y)) such that ai=bi a i = b i for all 1i<k 1 ≤ i < k and ak<bk a k < b k , or ai=bi a i = b i for all 1imin(x,y) 1 ≤ i ≤ min ( x , y ) and x<y x < y .

题目传送门

/*
* Doki Doki Literature Club
* 这题就是废话多,就两句话有用,最后注意下爆int的子项
*/

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
#define len 102
struct data{
    string _s;
    int key;
}map[102];

int cmp(data _a,data _b)
{

    if( _a.key == _b.key)   return _a._s < _b._s;   // 比赛的时候抽了 自己重写了 '<'
    return _a.key > _b.key ;
}

int main()
{
    int n,m;
    int test;
    //模版可忽略
    static_cast<void>(ios::sync_with_stdio(false)),cin.tie(0);

    cin>>test;

    while(test--)
    {
        cin>>n>>m;
        long long ans = 0;
        for(int i=1;i<=n;++i)
        {
            cin>>map[i]._s>>map[i].key;
        }

        sort(map+1, map+n+1, cmp);

        for (long i =1; i<=m; ++i) {
            ans += (m-i+1)*map[i].key;
        }

        cout<<ans;

        for(int i=1;i<=m;++i)
        {
            cout<<" "<< map[i]._s ;
        }
        cout<<endl;
    }
    return 0;
}

Created By LosReturn.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值