153 - The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple L题

题目传送门:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5761

简单题!!!!!

当时居然想这么复杂的做法!

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <string>

using namespace std;
struct pos
{
    string words;
    int v;
};
pos w[1000];
bool cmp(pos a,pos b)
{
    if(a.v==b.v) return a.words<b.words;
    else return a.v>b.v;
}

int main()
{
    ios::sync_with_stdio(false);
    long long T,n,m,ans;
    cin>>T;
    while(T--){
        cin>>n>>m;
        ans=0;
        for(int i=0;i<n;i++){
            cin>>w[i].words>>w[i].v;
        }
        sort(w,w+n,cmp);
        for(int i=0;i<m;i++){
            ans+=w[i].v*(m-i);
        }
        cout<<ans;
        for(int i=0;i<m;i++){
            cout<<" "<<w[i].words;
        }
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sinat_40948489/article/details/80162489