CSU-ACM2017暑期训练1-Debug与STL Jury Marks-set判重

题目:

C. Jury Marks


time limit per test 2 seconds

memory limit per test     256 megabytes


Polycarp watched TV-show wherek jury members one by one rated aparticipant 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 thei-th jury member gave ai points.

Polycarp does not remember how many points the participant hadbefore this k marks were given, but he remembers that among the scoresannounced after each of thek judges rated the participant there were n (n ≤ k) values b1, b2, ..., bn (it is guaranteed that allvalues bj are distinct). It ispossible 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 scorethe participant could have before the judges rated the participant.

Input

The first line contains two integersk and n (1 ≤ n ≤ k ≤ 2 000) —the number of jury members and the number of scores Polycarp remembers.

The second line containsk integers a1, a2, ..., ak ( - 2 000 ≤ ai ≤ 2 000) — jury's marks in chronological order.

The third line containsndistinct integers b1, b2, ..., bn ( - 4 000 000 ≤ bj ≤ 4 000 000) — the values of points Polycarp remembers. Note that thesevalues are not necessarily given in chronological order.

Output

Print the number of options for the score the participant could have before thejudges rated the participant. If Polycarp messes something up and there is nooptions, 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 is3 because initially the participantcould have  - 10,10 or 15 points.

In the second example there is only one correct initial score equaling to4 002 000.

 

题目大意:

给你一串评委给打的分,再给你一串中间分值(由初始分值加上某前一段评委打的分算得),问你初始分值有多少种可能?

思路:

随便取一个中间分值,与所有的评委打分的时间点枚举算初始分,再用set判重法来判断这个初始分数能不能满足其他的中间分值,注意判断所得初始分结果有没有重复。因为由一个中间分值和各个节点枚举出来的初始分可能重复。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;


int n,k,sco,ans;
int a[2222],b[2222];
set<int>s;
set<int>score;


int judge(int t)
{
s.erase(s.begin(),s.end());
    for(int i=0;i<k;i++)
    {
        s.insert(sco+a[i]);
    }
    for(int i=0;i<n;i++)
    {
    if(s.find(b[i])==s.end())
    return 0;
}
    return 1;
}


int main()
{
    while(scanf("%d%d",&k,&n)!=EOF)
    {
        score.erase(score.begin(),score.end());
        ans=0;
        for(int i=0;i<k;i++)
        {
            scanf("%d",&a[i]);
            if(i)
                a[i]+=a[i-1];
        }
        for(int i=0;i<n;i++)
        {
            scanf("%d",&b[i]);
        }
        for(int i=0;i<k;i++)
        {
            sco=b[0]-a[i];
            if(score.find(sco)==score.end()&&judge(i))
            {
                score.insert(sco);
                ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值