题解
2024-04-01 21:45:40
发布于:陕西
2阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n, m, v[110], minv = 0, maxv = 0;
struct fruit{
string name;
int num;
}arr[110];
bool com(fruit a, fruit b) {
return a.num < b.num;
}
bool comn(int a, int b) {
return a < b;
}
string s;
int top;
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
sort(v, v + n, comn);
bool ad;
for (int i = 0; i < m; ++i) {
cin >> s;
ad = false;
for (int j = 0; j < top; ++j) {
if (arr[j].name == s) {
++arr[j].num;
ad = true;
break;
}
}
if (!ad) {
arr[top].name = s;
arr[top].num = 1;
++top;
}
}
sort(arr, arr + top, com);
for (int i = 0; i < top; ++i) {
minv += v[i] * arr[top - i - 1].num;
maxv += v[n - i - 1] * arr[top - i - 1].num;
}
cout << minv << " " << maxv << endl;
cout << "拒绝抄袭,共建和谐acgo" << endl;
cout << "你个天才!都能把这两句话超下来!" << endl;
return 0;
}
这里空空如也
有帮助,赞一个