Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法...

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.


  题目大意 给定数组a和b, b[i]是a的某一个前缀和再加上一个x,问可能的x有多少个。

  如果存在解,说明b[1]至少是a的一个前缀和加上x得来的。所以我们暴力去枚举b[1]是a的哪一个前缀和,然后遍历一下b数组,判断对应的前缀和是否存在。因为懒,直接lower_bound完事。

Code

 1 /**
 2  * Codeforces
 3  * Problem#831C
 4  * Accepted
 5  * Time:78ms
 6  * Memory:2100k
 7  */
 8 #include <iostream>
 9 #include <cstdio>
10 #include <ctime>
11 #include <cmath>
12 #include <cctype>
13 #include <cstring>
14 #include <cstdlib>
15 #include <fstream>
16 #include <sstream>
17 #include <algorithm>
18 #include <map>
19 #include <set>
20 #include <stack>
21 #include <queue>
22 #include <vector>
23 #include <stack>
24 #include <cassert>
25 #ifndef WIN32
26 #define Auto "%lld"
27 #else
28 #define Auto "%I64d"
29 #endif
30 using namespace std;
31 typedef bool boolean;
32 const signed int inf = (signed)((1u << 31) - 1);
33 const signed long long llf = (signed long long)((1ull << 61) - 1);
34 const double eps = 1e-6;
35 const int binary_limit = 128;
36 #define smin(a, b) a = min(a, b)
37 #define smax(a, b) a = max(a, b)
38 #define max3(a, b, c) max(a, max(b, c))
39 #define min3(a, b, c) min(a, min(b, c))
40 template<typename T>
41 inline boolean readInteger(T& u){
42     char x;
43     int aFlag = 1;
44     while(!isdigit((x = getchar())) && x != '-' && x != -1);
45     if(x == -1) {
46         ungetc(x, stdin);    
47         return false;
48     }
49     if(x == '-'){
50         x = getchar();
51         aFlag = -1;
52     }
53     for(u = x - '0'; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x - '0');
54     ungetc(x, stdin);
55     u *= aFlag;
56     return true;
57 }
58 
59 int n, m, k;
60 int* a;
61 int* sa;
62 int* b;
63 
64 inline void init() {
65     readInteger(n);
66     readInteger(k);
67     a = new int[n + 1];
68     b = new int[k + 1];
69     sa = new int[n + 1];
70     sa[0] = 0;
71     for(int i = 1; i <= n; i++) {
72         readInteger(a[i]);
73         sa[i] = sa[i - 1] + a[i];
74     }
75     for(int i = 1; i <= k; i++)
76         readInteger(b[i]);
77 }
78 
79 int res;
80 inline void solve() {
81     sort(sa + 1, sa + n + 1);
82     res = m = unique(sa + 1, sa + n + 1) - sa - 1;
83     for(int i = 1; i <= m; i++) {
84         int s = b[1] - sa[i];
85         for(int j = 2; j <= k; j++) {
86             if(*lower_bound(sa + 1, sa + m + 1, b[j] - s) != b[j] - s) {
87                 res--;
88                 break;
89             }
90         }
91     }
92     printf("%d\n", res);
93 }
94 
95 int main() {
96     init();
97     solve();
98     return 0;
99 }

 

转载于:https://www.cnblogs.com/yyf0309/p/7170956.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧农业是一种结合了现代信息技术,包括物联网、大数据、云计算等,对农业生产过程进行智能化管理和监控的新模式。它通过各种传感器和设备采集农业生产中的关键数据,如大气、土壤和水质参数,以及生物生长状态等,实现远程诊断和精准调控。智慧农业的核心价值在于提高农业生产效率,保障食品安全,实现资源的可持续利用,并为农业产业的转型升级提供支持。 智慧农业的实现依赖于多个子系统,包括但不限于设施蔬菜精细化种植管理系统、农业技术资料库、数据采集系统、防伪防串货系统、食品安全与质量追溯系统、应急追溯系统、灾情疫情防控系统、农业工作管理系统、远程诊断系统、监控中心、环境监测系统、智能环境控制系统等。这些系统共同构成了一个综合的信息管理和服务平台,使得农业生产者能够基于数据做出更加科学的决策。 数据采集是智慧农业的基础。通过手工录入、传感器自动采集、移动端录入、条码/RFID扫描录入、拍照录入以及GPS和遥感技术等多种方式,智慧农业系统能够全面收集农业生产过程中的各种数据。这些数据不仅包括环境参数,还涵盖了生长状态、加工保存、检验检疫等环节,为农业生产提供了全面的数据支持。 智慧农业的应用前景广阔,它不仅能够提升农业生产的管理水平,还能够通过各种应用系统,如库房管理、无公害监控、物资管理、成本控制等,为农业生产者提供全面的服务。此外,智慧农业还能够支持政府监管,通过发病报告、投入品报告、死亡报告等,加强农业产品的安全管理和质量控制。 面对智慧农业的建设和发展,存在一些挑战,如投资成本高、生产过程标准化难度大、数据采集和监测的技术难题等。为了克服这些挑战,需要政府、企业和相关机构的共同努力,通过政策支持、技术创新和教育培训等手段,推动智慧农业的健康发展。智慧农业的建设需要明确建设目的,选择合适的系统模块,并制定合理的设备布署方案,以实现农业生产的智能化、精准化和高效化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值