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;
}

codeforces #577(Div.2)的更多相关文章

  1. Codeforces Round #577 (Div. 2) D. Treasure Hunting

    Codeforces Round #577 (Div. 2)  D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...

  2. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  3. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  4. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  5. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  6. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

  7. codeforces #578(Div.2)

    codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...

  8. codeforces #332 div 2 D. Spongebob and Squares

    http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...

  9. 矩阵拿宝物--Codeforces 1201D - Treasure Hunting Codeforces Round #577 (Div. 2)

    网上题解比较少,自己比较弱研究了半天(已经过了),希望对找题解的人有帮助 题目链接:https://codeforc.es/contest/1201/problem/D 题意: 给你一个矩形,起始点在 ...

随机推荐

  1. 构建根文件系统之init进程分析

    busybox是ls.cp等命令的集合. 执行ls时,实际上是执行了busybox ls 执行cp时,实际上是执行了busybox cp 分析init程序之前,再让我们回想一下我们的目标:u-boot ...

  2. 【餐厅】 What kind of food would you like to eat tonight?

    核心句型 What kind of food would you like to eat tonight? 你今晚想吃哪种菜? What would you like to eat ? 你想吃什么? ...

  3. day24_7.30 反射与元类

    一.反射 在python中,反射通常是指一个对象应该具备,可以检测修复,增加自身属性的能力. 而反射可以通过字符串对其进行操作. 其中涉及了4个函数,是四个普通 的函数: hasattr(oop,st ...

  4. 继上篇博客对安卓爬虫以及TextView更新的问题解释

    只能在主线程更新ui,或者用handler传输.爬虫是在另一个异步线程进行,所以爬出来的数据对控件赋值就比较麻烦.这次使用了线程数据传到runnable将数据传到handler进行赋值. 结果图: 源 ...

  5. Task异常捕获的几种方式

    在调用Task的Wait()方法或Result属性处会抛出Task中的异常. 但是如果没有返回结果,或者不想调用Wait()方法,该怎么获取异常呢? 可以使用ContinueWith()方法 var ...

  6. 遵循PEP8风格

    遵循PEP8风格 在编写python代码的时候我们应该采用统一的风格来编写代码,可以使代码更加容易读懂.采用和其他程序员统一的编码风格来写代码,也可以使项目更利于多人协作开发.即便代码只有你自己能看懂 ...

  7. ESP8266 LUA脚本语言开发: 准备工作-LUA开发是怎么来的

    前言 当前8266有各种开发 1.在官方已经封装好的C库上开发(SDK开发) 2.官方在SDK的基础上封装的AT指令程序(AT指令开发) 3.在SDK的基础上嵌入脚本语言(Lua,Python等开发方 ...

  8. cf1039D 分块

    cf1039D 链接 cf 思路 一次k可以贪心O(n)算. 对于\(≤\sqrt{n}\)的k,暴力算. 对于\(>\sqrt{n}\)的k,最多会有\(\sqrt{n}\)种答案,而且答案单 ...

  9. 忍者钩爪 ( ninja) 题解———2019.10.19

    可以到这里测..嘿嘿嘿 题目: [问题 描述 ] 小 Q 是一名酷爱钩爪的忍者, 最喜欢飞檐走壁的感觉, 有一天小 Q 发现一个练习使用钩 爪的好地方,决定在这里大显身手. 场景的天花板可以被描述为一 ...

  10. Centos 7使用docker部署LAMP搭建wordpress博客系统

    0.简要概述 LAMP是目前比较流行的web框架,即Linux+Apache+Mysql+PHP的网站架构方案.docker是目前非常流行的虚拟化应用容器,可以为任何应用创建一个轻量级.可移植的容器. ...