codeforces #577(Div.2)

codeforces #577(Div.2)

A  Important Exam

 

A class of students wrote a multiple-choice test.

There are nn students in the class. The test had mm questions, each of them had 55 possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question ii worth aiai 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 nn and mm (1≤n,m≤10001≤n,m≤1000) — the number of students in the class and the number of questions in the test.

Each of the next nn lines contains string sisi (|si|=m|si|=m), describing an answer of the ii-th student. The jj-th character represents the student answer (A, B, C, D or E) on the jj-th question.

The last line contains mm integers a1,a2,…,ama1,a2,…,am (1≤ai≤10001≤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 1616.

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=215+4+12=21.

題意:學生考完試後想算成績,但他們不知道正確答案,只是每個人都記住了自己填寫的答案,最後一行輸入每個題目如果正確的話其得分爲多少。讓你算一下答案由你來決定的話,它們總分最多是多少,輸出這個總分即可。每道題目最多有五個選項。

思路:算出每個題中選項最多的答案數量,再乘以改題正確的分數。代碼如下:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
int const maxn=1001;
struct node{
	string a;
}q[maxn];
int main()
{
	int n,k,x;
	LL sum=0;
	int s[5];
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		cin>>q[i].a;
	}
	for(int i=0;i<k;i++){
		scanf("%d",&x);
		memset(s,0,sizeof(s));
		for(int j=0;j<n;j++){
			if(q[j].a[i]=='A')s[0]++;
			if(q[j].a[i]=='B')s[1]++;
			if(q[j].a[i]=='C')s[2]++;
			if(q[j].a[i]=='D')s[3]++;
			if(q[j].a[i]=='E')s[4]++;
		}
		sum+=x*max(s[0],max(s[1],max(s[2],max(s[3],s[4]))));
	}
	cout<<sum<<endl;
	return 0;
}

B.Zero Array

 

You are given an array a1,a2,…,ana1,a2,…,an.

In one operation you can choose two elements aiai and ajaj (i≠ji≠j) and decrease each of them by one.

You need to check whether it is possible to make all the elements equal to zero or not.

Input

The first line contains a single integer nn (2≤n≤1052≤n≤105) — the size of the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output

Print "YES" if it is possible to make all elements zero, otherwise print "NO".

Examples

input

4
1 1 2 2

output

YES

input

6
1 2 3 4 5 6

output

NO

Note

In the first example, you can make all elements equal to zero in 33 operations:

  • Decrease a1a1 and a2a2,
  • Decrease a3a3 and a4a4,
  • Decrease a3a3 and a4a4

In the second example, one can show that it is impossible to make all elements equal to zero.

題意: 輸入一組數,每次選其中兩個數,使這兩個數都減一。輸入的數能否全都減爲0。能的話輸出“YES”,不能的話輸出“NO”。

思路:計算所有數的和,和爲奇數肯定不行,和爲偶數有可能。但當某個數比其他所有數的和都大時也不行。代碼如下:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
int const maxn=100001;
bool cmp(int a,int b){return a>b;}
int main(){
	int n;
	int a[maxn];
	LL sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n,cmp);
	if(sum%2==0&&sum-a[0]>=a[0])printf("YES\n");
	else printf("NO\n");
	return 0;
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章