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.
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.
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).
4 1
-5 5 0 20
10
3
2 2
-2000 -2000
3998000 4000000
1
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 ;
}