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.


  题目大意 给定数组a和b, b[i]是a的某一个前缀和再加上一个x,问可能的x有多少个。

  如果存在解,说明b[1]至少是a的一个前缀和加上x得来的。所以我们暴力去枚举b[1]是a的哪一个前缀和,然后遍历一下b数组,判断对应的前缀和是否存在。因为懒,直接lower_bound完事。

Code

 /**
* Codeforces
* Problem#831C
* Accepted
* Time:78ms
* Memory:2100k
*/
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <stack>
#include <cassert>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;
const signed int inf = (signed)((1u << ) - );
const signed long long llf = (signed long long)((1ull << ) - );
const double eps = 1e-;
const int binary_limit = ;
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} int n, m, k;
int* a;
int* sa;
int* b; inline void init() {
readInteger(n);
readInteger(k);
a = new int[n + ];
b = new int[k + ];
sa = new int[n + ];
sa[] = ;
for(int i = ; i <= n; i++) {
readInteger(a[i]);
sa[i] = sa[i - ] + a[i];
}
for(int i = ; i <= k; i++)
readInteger(b[i]);
} int res;
inline void solve() {
sort(sa + , sa + n + );
res = m = unique(sa + , sa + n + ) - sa - ;
for(int i = ; i <= m; i++) {
int s = b[] - sa[i];
for(int j = ; j <= k; j++) {
if(*lower_bound(sa + , sa + m + , b[j] - s) != b[j] - s) {
res--;
break;
}
}
}
printf("%d\n", res);
} int main() {
init();
solve();
return ;
}

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法的更多相关文章

  1. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  2. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组

    Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块

    Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...

  6. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  7. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

  8. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...

  9. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C

    A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...

随机推荐

  1. 已解决(转)关于android - apk(解析错误)解析程序包时出现问题

    如果开发的应用用户较多,那么必须保证应用在多个版本不同的设备上能够正确的运行.这就要求对各个版本比较熟悉,知道在什么版本中加入了什么新的功能或特性.但是Android的版本太多了,是个令人头疼的问题. ...

  2. list.remove出错 报 Not source之类的错误

    private static String removePreviousString(String str,String strPre){ String[] strArray = str.split( ...

  3. Flume:sink.type=hive

    Flume以Kafka为Source,以Hive为Sink进行数据转存. 业务背景:公司要求将某四川城市的卡口数据实时接入大数据平台中,历史数据可以通过Hive进行Load,也就是增量数据的对接问题. ...

  4. CSS选择器的优先级及权重问题【CSS核心问题】及其它属性

    1.CSS选择器优先级:    !important >行间样式> id >class和属性选择器>标签选择器>通配符选择器        注意:[初级工程师水平] 2. ...

  5. Oracle10g 连接 sqlserver 在server2008r2 中连接 iis7 .net4.0

    一.做好了连接但是到了64位的server2008r2上就是不行,报错dns上不匹配.最后找到原因了 自己到c盘里面找32位的odbc管理工具然后建立连接,然后一切正常. 二.iis7 .net4.0 ...

  6. Spark学习之路 (十八)SparkSQL简单使用

    一.SparkSQL的进化之路 1.0以前: Shark 1.1.x开始: SparkSQL(只是测试性的)  SQL 1.3.x: SparkSQL(正式版本)+Dataframe 1.5.x: S ...

  7. 【Scala学习之一】 Scala基础语法

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk1.8 scala-2.10.4(依赖jdk1.8) spark ...

  8. CodeReview实践与总结

    CodeReview 是大型软件工程中公认的必不可少的保证工程质量的重要手段之一.但凡正规软件作战军团都是非常重视 CodeReview 的作用和意义的.那么,如何做好 CodeReview 呢?这里 ...

  9. 20165305 苏振龙《Java程序设计》第七周学习总结

    第十一章 JDBC技术在数据库开发中占有很重要的地位,JDBC操作不同的数据库仅仅是连接方式上的差异而已,使用JDBC的应用程序一旦和数据库建立连接,就可以使用JDBC提供的API操作数据库. 当查询 ...

  10. 设计模式之Mediator(中介者)(转)

    Mediator定义: 用一个中介对象来封装一系列关于对象交互行为. 为何使用Mediator? 各个对象之间的交互操作非常多;每个对象的行为操作都依赖彼此对方,修改一个对象的行为,同时会涉及到修改很 ...