跳到正文

个人记录

为

deepshits约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年3月15日
收录
2026年3月15日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
using namespace std;
map<string,int> a;
int b[101],t[101];
int ba[101];
bool cmp(pair<string,int> x,pair<string,int> y){
    return x.second>y.second;
}
int main(){
    int n,m,ans=0,cnt=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    sort(b+1,b+n+1);
    int d=1,ne=n;
    for(int i=1;i<=m;i++){
        string w;
        cin>>w;
        a[w]++;
    }
    vector<pair<string,int> >v(a.begin(),a.end());
    sort(v.begin(),v.end(),cmp);
    for(auto ew:v){
        ans+=b[ne]*ew.second;
        cnt+=b[d]*ew.second;
        d++;
        ne--;
    }
    cout<<cnt<<' '<<ans;
    return 0; 
}
原文