C. Jury Marks
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.

Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that all values bj are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.

Your task is to determine the number of options for the score the participant could have before the judges rated the participant.

Input

The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.

The second line contains k integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order.

The third line contains n distinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.

Output

Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).

Examples
input
4 1
-5 5 0 20
10
output
3
input
2 2
-2000 -2000
3998000 4000000
output
1
Note

The answer for the first example is 3 because initially the participant could have  - 10, 10 or 15 points.

In the second example there is only one correct initial score equaling to 4 002 000.

昨天写的题了,打完多校后拿出来看了看改了改参数就过了。。。

AC代码:

 #include<bits/stdc++.h>
using namespace std; int sum[];
vector<int> vec;
map<int,int> mp; int main(){
int n,k;
int x;
cin>>k>>n;
memset(sum,,sizeof(sum));
for(int i=;i<=k;i++){
cin>>x;
sum[i]=sum[i-]+x;
}
sort(sum+,sum++k);
int len=unique(sum+,sum++k)-(sum+);//去重后的长度
//cout<<len<<endl;
for(int i=;i<n;i++){
cin>>x;
for(int j=;j<=len;j++){
int temp=x-sum[j];
vec.push_back(temp);
}
}
sort(vec.begin(),vec.end());
for(int i=;i<vec.size();i++){
mp[vec[i]]++;
}
int num=;
for(int i=;i<vec.size();i++){
if(mp[vec[i]]>=n){
num++;
mp[vec[i]]=;
}
}
cout<<num<<endl;
return ;
}

CF-831C的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  10. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

随机推荐

  1. MySQL-获取某天的数据

    今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 近7天 DAY) <= date(时间字段名) 近30天 DAY) & ...

  2. dubbo 实战1

    准备:先安装zookeeper,然后进入一下步骤 服务端 1.新建 maven项目 2.pom.xml 内容如下 <?xml version="1.0" encoding=& ...

  3. KMP算法模式匹配

    转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/37832707 作者:小马 在一个长串中查找一个子串是较经常使用的操作.各种信息检索 ...

  4. 多媒体开发之---h.264 SPS PPS解析源代码,C实现一以及nal分析器

    http://blog.csdn.net/mantis_1984/article/details/9465909 http://blog.csdn.net/arau_sh/article/detail ...

  5. 继承的文本框控件怎么响应EN_CHANGE等消息

    继承的文本框控件如何响应EN_CHANGE等消息?我从CEdit继承了一个CMyEdit类,想在这个类里填写它的一些消息.我在消息映射表里写的是MESSAGE_HANDLER(EN_CHANGE, O ...

  6. 九度OJ 1121:首字母大写 (字符串处理)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2865 解决:1007 题目描述: 对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母. 在字符串中,单词 ...

  7. win10安装VMware

    首先下载VMware安装包: 双击安装: 点击:“uninstall”安装,这个过程需要一些时间 点击“Next” 选择典型或者自定义安装 这里我选择的是典型安装,点击“Next”: 选择是否检查更新 ...

  8. UIView封装动画--iOS 利用系统提供方法来做弹性运动

    iOS 利用系统提供方法来做弹性运动 /*创建弹性动画 damping:阻尼,范围0-1,阻尼越接近于0,弹性效果越明显 velocity:弹性复位的速度 */ [UIView animateWith ...

  9. iOS 打开应用与系统功能的调用

    [[UIApplication sharedApplication] openURL:url]; 通过给url不同的值,可以实现调用系统自带 电话/短信/邮箱/浏览器/...   1.调用 电话pho ...

  10. leeetcode 735. Asteroid Collision

    We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the ...