zoukankan      html  css  js  c++  java
  • CF-831C

    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.

    昨天写的题了,打完多校后拿出来看了看改了改参数就过了。。。

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int sum[2010]; 
     5 vector<int> vec;
     6 map<int,int> mp;
     7 
     8 int main(){
     9     int n,k;
    10     int x;
    11     cin>>k>>n;
    12     memset(sum,0,sizeof(sum));
    13     for(int i=1;i<=k;i++){
    14         cin>>x;
    15         sum[i]=sum[i-1]+x;
    16     }
    17     sort(sum+1,sum+1+k);
    18     int len=unique(sum+1,sum+1+k)-(sum+1);//去重后的长度 
    19     //cout<<len<<endl; 
    20     for(int i=0;i<n;i++){
    21         cin>>x;
    22         for(int j=1;j<=len;j++){
    23             int temp=x-sum[j];
    24             vec.push_back(temp);
    25         }
    26     }
    27     sort(vec.begin(),vec.end());
    28     for(int i=0;i<vec.size();i++){
    29         mp[vec[i]]++;
    30     }
    31     int num=0;
    32     for(int i=0;i<vec.size();i++){
    33         if(mp[vec[i]]>=n){
    34             num++;
    35             mp[vec[i]]=0;
    36         }
    37     }
    38     cout<<num<<endl;
    39     return 0;
    40 } 
  • 相关阅读:
    [转]vc中socket编程步骤
    [转载]使用命名管道实现进程间通信
    换肤软件摘要
    3D 专业词汇 (转)
    如何从 Microsoft DirectShow 筛选器图形获取数据(转)
    “人大艺术学院”“赵雅芝中文网”等网站被挂马 狼人:
    微软将发布5月安全漏洞补丁 修补PPT 狼人:
    专家提醒:网络挂马借“海运女”传播 狼人:
    黑客借“甲型流感”传毒 挂马疾病预防控制中心网站 狼人:
    黑客称攻破乔布斯亚马逊网站账户 欲售相关信息 狼人:
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/7236341.html
Copyright © 2011-2022 走看看