CodeForces - 831C Jury Marks 思维题

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 bjare 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).

Example
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output

1


完全不会做..看网上的题解看了好久才明白..真是怕了这种题了..


首先需要注意的是评委给的分数是有顺序的,从左到右的,这一点我们需要注意。

所以我们利用sum求前缀和即可。

之后我们对于某个初始值,要加上sum值,满足所有的过程分数。

我们图方便,从固定的某一个过程分开始计算。

对于第一个过程分,我们是第x个评委后得到的。所以原始分就是b【0】-sum【x】。

之后我们要保证其他已知过程分都在这个原始分经过所有sum之后的分数中。


#include<iostream>
#include<algorithm>
using namespace std;
int sum[2100];
int a[2100],b[2100];
int main()
{
    int n,m;
    sum[0]=0;
    int shuchu=0;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum[i+1]=sum[i]+a[i];
    }
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
    }
    sort(sum+1,sum+1+n);
    n=unique(sum+1,sum+1+n)-(sum+1);
    int ans=n;
    for(int i=1;i<=n;i++)//对于所有的评委分
    {
        int chushifen=b[0]-sum[i];
        for(int j=1;j<m;j++)//对于其他过程分
        {
            int xuyaochazhi=b[j]-chushifen;
            if(!binary_search(sum+1,sum+1+n,xuyaochazhi))//s没有找到,说明这个初始分不合格
            {
                ans--;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值