-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
37 lines (36 loc) · 677 Bytes
/
Copy pathC.cpp
File metadata and controls
37 lines (36 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,x;
string s;
cin>>n>>m;
vector <int> v(n),a;
map<string,int> mp;
for(int i=0;i<n;i++)
cin>>v[i];
for(int i=0;i<m;i++)
{
cin>>s;
mp[s]++;
}
for(auto it=mp.begin();it!=mp.end();it++)
{
x=it->second;
a.push_back(x);
}
sort(v.begin(),v.end());
sort(a.begin(),a.end(),greater<int>());
int c1=0,c2=0;
for(int i=0;i<a.size();i++)
{
c1+=a[i]*v[i];
}
sort(v.begin(),v.end(),greater<int>());
for(int i=0;i<a.size();i++)
{
c2+=a[i]*v[i];
}
cout<<c1<<' '<<c2;
return 0;
}