CodeForces
来源:互联网 发布:网络抽奖 编辑:程序博客网 时间:2024/06/04 19:31
Description
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).
Example
Input4 1-5 5 0 2010Output3Input2 2-2000 -20003998000 4000000Output1
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.
题意:
某人具有一个原始分数,经n个评委对分数进行加减,已知n个评委依次给出的分数和m个暂时总分(经某个评委给分后的暂时总分,乱序),问能求出多少种原始分数。
题解:
设原始分数为x,先求出一个x,再看看这个x是否符合其他的条件。详解如下:
#include <iostream>#include <string>#include <vector>#include <cstdio>#include<algorithm>using namespace std;int a[2005], b[2005];int main(){ //freopen("data.in", "r", stdin); int n, m; while (~scanf("%d%d", &n, &m)) { scanf("%d", &a[0]); int temp; for (int i = 1; i < n; i++) { scanf("%d", &temp); a[i] = a[i - 1] + temp;//a[i]记录评委给分的前缀和,便于求x } for (int i = 0; i < m; i++) { scanf("%d", &b[i]); } sort(a, a + n);//对a进行排序和去重 int *end = unique(a, a + n);//去重函数需要在sort之后调用,返回最后一个元素的指针 int ans = 0; for (int *i = a; i < end; i++) { bool flag = true; int x = b[0] - *i;//求一个原始分数x for (int j = 1; j < m; j++) {//判断x能否满足其他条件 if (!binary_search(a, end, b[j] - x)) { flag = false; break; } } if (flag) ans++; } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- h3c交换机combo口的应用
- AUC ROC
- 防火墙配置
- 系统相关功能开发(二)-磁盘操作
- 最大熵模型总结
- CodeForces
- 【CodeForces
- 利用poi操作execl添加行和列
- [前端]TAG标签输入的实现
- Node.js腾讯云COS文件上传
- 迅捷CAD转换器怎么把CAD转换成jpg
- idea断点
- JSON详解
- Cardboard实现VR的目选效果