Codeforces Round #577 (Div. 2)
A class of students wrote a multiple-choice test.
There are n students in the class. The test had m questions, each of them had 5 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question i worth ai points. Incorrect answers are graded with zero points.
The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class.
Input
The first line contains integers n and m (1≤n,m≤1000) — the number of students in the class and the number of questions in the test.
Each of the next n lines contains string si (|si|=m), describing an answer of the i-th student. The j-th character represents the student answer (A, B, C, D or E) on the j-th question.
The last line contains m integers a1,a2,…,am (1≤ai≤1000) — the number of points for the correct answer for every question.
Output
Print a single integer — the maximum possible total score of the class.
Examples
input
2 4
ABCD
ABCE
1 2 3 4
output
16
input
3 3
ABC
BCD
CDE
5 4 12
output
21
Note
In the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be 16.
In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is 5+4+12=21.
题意:题目意思就是有n个学生,m道题目,给出n个学生对m道题目做出的选项 ABCD...和每道题的分数 ,
然后让你给每道题选择一个答案,使学生的总分最高。
思路:直接每次看一道题,找出最多的选项加分,
注意题目给出的分数是每道题的分数,而不是选项的分数。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<map> 7 #include<set> 8 #include<vector> 9 #include<queue> 10 #include<list> 11 //#include<unordered_map> 12 #include<stack> 13 using namespace std; 14 #define ll long long 15 #define dd cout<<endl 16 const int mod=1e9+7; 17 const int inf=1e9+7; 18 19 const int maxn=1e3+10; 20 21 string str[maxn]; 22 23 int point[maxn]; 24 25 int main() 26 { 27 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); 28 29 int n,m; 30 31 cin>>n>>m; 32 33 for(int i=0;i<n;i++) 34 cin>>str[i]; 35 36 for(int i=0;i<m;i++) 37 cin>>point[i]; 38 39 map<char,int>mp1; 40 41 ll int sum=0; 42 for(int i=0;i<m;i++) 43 { 44 mp1.clear(); 45 ll int maxx=-1; 46 ll int mark_I=0; 47 for(int j=0;j<n;j++) 48 { 49 mp1[str[j][i]]++; 50 51 if(mp1[str[j][i]]>maxx) 52 { 53 mark_I=(str[j][i]-'A'); 54 maxx=mp1[str[j][i]]; 55 } 56 } 57 sum+=point[i]*maxx; 58 59 // cout<<mark_I<<" "<<maxx<<endl; 60 } 61 62 cout<<sum<<endl; 63 64 return 0; 65 }