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.
Sample Input
4
10 8
hello 0
world 0
behind 0
far 1
be 2
spring 10
can 15
comes 20
winter 25
if 200
5 5
collegiate 0
programming -5
zhejiang 10
provincial 5
contest -45
3 2
bcda 1
bcd 1
bbbbb 1
3 2
a 1
aa 1
aaa 1
Sample Output
2018 if winter comes can spring be far behind
15 zhejiang provincial collegiate programming contest
3 bbbbb bcd
3 a aa
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct node
{
char w[15];
long long int h;
}p[101];
bool cmp(struct node p,struct node q)
{
if(p.h==q.h)
return p.w<q.w;
else return p.h>q.h;
}
int main()
{
int i,n,m,T;
long long int sum;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%s %lld",p[i].w,&p[i].h);
}
sort(p,p+n,cmp);
sum=0;
for(i=0;i<m;i++)
{
sum+=(m-i)*p[i].h;
}
printf("%lld",sum);
for(i=0;i<m;i++)
{
printf(" %s",p[i].w);
}printf("\n");
}
return 0;
}