Doki Doki Literature Club
题解:其实就是简单排序输出就没了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
struct node {
ll w;
char name[25];
}s[500];
bool cmp(struct node a, struct node b)
{
return a.w > b.w;
}
int main()
{
ll t,n,m,sum;
scanf("%lld",&t);
while(t--)
{
scanf("%lld %lld", &n,&m);
for(ll i = 1; i <= n; i ++)
{
getchar();
scanf("%s %lld", s[i].name, &s[i].w);
// cout << s[i].name << endl;
}
sort(s + 1, s + n + 1, cmp);
sum = 0;
for(ll i = 1; i <= m; i ++)
{
sum = sum + (s[i].w *(m - i + 1));
}
printf("%lld ",sum);
for(ll i = 1; i <= m; i ++)
{
if(i == 1)printf("%s",s[i].name);
else printf(" %s",s[i].name);
}
printf("
");
}
return 0;
}