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. windows下通过VNC图形化訪问Ubuntu桌面环境

    要在windows下图形化訪问Ubuntu或其他Linux系统桌面环境有非常多方法.我比較喜欢的是使用VNC服务,须要在Ubuntu下安装vncserver和在windows下安装client訪问工具 ...

  2. KMP算法模式匹配

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

  3. Ajax技术实现页面无刷新跳转

    Ajax实现无刷新显示新的页面 <!DOCTYPE html> <html> <head> <script src="/jquery/jquery- ...

  4. iOS进程间通信之CFMessagePort

    本文转载至 http://www.cocoachina.com/industry/20140606/8701.html iOS系统是出了名的封闭,每个应用的活动范围被严格地限制在各自的沙盒中.尽管如此 ...

  5. Interface AutoCloseable

    https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html https://docs.oracle.com/javase ...

  6. Redis persistence demystified

    https://redis.io/topics/persistence http://oldblog.antirez.com/post/redis-persistence-demystified.ht ...

  7. Recurrent neural networks are very powerful, because they combine two properties

    https://www.cs.toronto.edu/~hinton/csc2535/notes/lec10new.pdf Distributed hidden state that allows t ...

  8. Java Message Service

    en.wikipedia.org/wiki/Java_Message_Service Messaging is a form of loosely coupled distributed commun ...

  9. 推荐一个非常好的 IntelliJ IDEA 教程

    教程地址:https://github.com/judasn/IntelliJ-IDEA-Tutorial 作者博客:http://www.youmeek.com/category/software- ...

  10. 【Effective C++】构造/析构/赋值运算

    条款05:了解C++默默编写并调用哪些函数 默认构造函数.拷贝构造函数.拷贝赋值函数.析构函数构成了一个类的脊梁,只有良好的处理这些函数的定义才能保证类的设计良好性. 当我们没有人为的定义上面的几个函 ...