您的位置:首页 > 其它

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

2017-07-14 09:43 543 查看
传送门

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.

题意:k个评审团。每个人有一个对你的评分。初始值不知道,下面n个数。现在问你有多少个初始值符合减去a[]的前缀和==b[i]并且b[i] 中n个数必须都满足。比如样例2 只有4002000满足条件 -2000之后为4000000,-4000之后为3998000满足下面所有的b[i]

做法。先对a[i]的前缀和排序。然后剔除重复的元素。 因为重复的元素对答案没有贡献。

然后求初始值。初始值必定满足b[1]-sum[1] 如果这个条件都不满足,肯定不是我们要的答案。所以最大会有k个初始值。

再遍历b[j]如果b[j]-初始值在前缀和里找不到肯定也不是我们要的答案

//china no.1#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
using namespace std;

#define pi acos(-1)
#define endl '\n'
#define rand() srand(time(0));
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e5+100;
const double EPS=1e-7;
const int MOD=10000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)

inline int Scan()
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')flag=1;
else if(ch>='0' && ch<='9')res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';
return flag ? -res : res;
}

int a[maxn],b[maxn],c[maxn];
int main()
{
int n,m;
cin>>n>>m;
FOR(1,n,i) cin>>a[i];
FOR(1,n,i) b[i]=b[i-1]+a[i];
sort(b+1,b+n+1);
n=unique(b+1,b+n+1)-b-1;//剔除重复元素
FOR(1,m,i) cin>>c[i];
int ans=n;
FOR(1,n,i)
{
int d=c[1]-b[i];
FOR(1,m,j)
if(!binary_search(b+1,b+n+1,c[j]-d))//二分查找c[j]-d的值是否存在
{
--ans;
break;
}
}
cout<<ans<<endl;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐