Codeforces831C Jury Marks
2 seconds
256 megabytes
standard input
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.
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.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
#define MAXN 2000010 int a[2010],b[2010];
int cnt[20000000]; int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
if(i) a[i]+=a[i-1];
}
for(int i=0;i<k;i++)
scanf("%d",&b[i]),b[i]+=10000000;
sort(a,a+n);
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<k;j++)
{
if(i&&a[i]==a[i-1])
continue;
cnt[b[j]-a[i]]++;
if(cnt[b[j]-a[i]]==k)
ans++;
}
}
printf("%d\n",ans);
return 0;
}
Codeforces831C Jury Marks的更多相关文章
- C. Jury Marks
C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- C. Jury Marks 思维
C. Jury Marks 这个题目虽然是只有1600,但是还是挺思维的. 有点难想. 应该可以比较快的推出的是这个肯定和前缀和有关, x x+a1 x+a1+a2 x+a1+a2+a3... x+s ...
- C. Jury Marks 思维题
http://codeforces.com/contest/831/problem/C 做的时候想不到,来了个暴力. 对于每个b[i],枚举每一个a[i],就有1个可能的情况. 然后用vector存起 ...
- CF831C Jury Marks
思路: 关键在于“插入”一个得分之后,其他所有得分也随之确定了. 实现: #include <iostream> #include <cstdio> #include < ...
- 【Codeforces Round #424 (Div. 2) C】Jury Marks
[Link]:http://codeforces.com/contest/831/problem/C [Description] 有一个人参加一个比赛; 他一开始有一个初始分数x; 有k个评委要依次对 ...
- #424 Div2 Problem C Jury Marks (二分 && 暴力 && std::unique && 思维)
题目链接 :http://codeforces.com/contest/831/problem/C 题意 :选手有一个初始积分,接下来有k个裁判为他加分或减分(时间顺序给出),然后告诉你n(1< ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)
http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) A 水 B stl C stl D 暴力 E 树状数组
A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CF-831C
C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- UVA 679 二叉树
题目链接:https://vjudge.net/problem/UVA-679 参考自:刘汝佳的紫书 思路: 我们发现,对于每一颗子树,假如小球是第奇数次到达这颗子树的根节点时,那么此时应该向左子树走 ...
- 安装IDEA的历程
安装IDEA的历程 写这篇博客的主要目的就是记录自己安装IDEA的"复杂"过程,顺便给一些需要帮助的人提供一些帮助,以及让他们可以少走一些弯路.之所以说"复杂" ...
- FortiGate 服务License注册步骤
1. 产品服务license文档 购买服务后,用户会收到一份PDF文档<Service Registration Document>,内有如下内容: 2. 登陆 https://suppo ...
- docker image 详解
docker iamge docker 镜像: [root@localhost ~]# docker image --help Usage: docker image COMMAND 管理镜像 Com ...
- shp2pgsql向postgresql导入shape数据
1. 准备好Shape文件(不仅仅是.shp文悠扬,还要有其他相关数据文件,包括.shx..prj..dbf文件). 2. 使用命令将Shape数据转换为*.sql文件 shp2pgsql -s 38 ...
- PHP整理--MySQL--DOS命令操作数据库
一.MySQL:关系型数据库,存在表的概念. MySQL的结构:数据库可以存放很多表,每张表可以存放多个字段,每个字段可以存放多个记录. 二.Dos操作数据库 用PHPStudy终端➡其他选项菜单➡M ...
- Numpy and Matplotlib
Numpy介绍 编辑 一个用python实现的科学计算,包括:1.一个强大的N维数组对象Array:2.比较成熟的(广播)函数库:3.用于整合C/C++和Fortran代码的工具包:4.实用的线性代数 ...
- AJAX随笔2
Ajax作用: 是用JavaScript向服务器发送异步请求,然后服务器给出响应,然后以XML格式的文件返回给浏览器端! 异步: 当浏览器向服务器发送请求的时候,不是整个页面刷新,而是局部刷新[局部信 ...
- random模块,生成随机数
1.random.choice(sep) 从一个序列中随机选取一个元素返回 >>> list1=["a",1,2,3,"b"] >> ...
- Game Theory
HDU 5795 || 3032 把x个石子的堆分成非空两(i, j)或三堆(i, j, k)的操作->(sg[i] ^ sg[j])或(sg[i] ^ sg[j] ^ sg[k])是x的后继 ...