[CF] 950B Intercepted Message
B. Intercepted Message
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.
Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive.
Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.
You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages.
The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message.
The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message.
It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106.
Output
Print the maximum number of files the intercepted array could consist of.
Examples
inputCopy
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8
output
3
inputCopy
3 3
1 10 100
1 100 10
output
2
inputCopy
1 4
4
1 1 1 1
output
1
Note
In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8.
In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100.
In the third example the only possibility is that the archive contains a single file of size 4.
既然要保证序列顺序不变,那么前缀和就具备各种优良的性质了。
//Stay foolish,stay hungry,stay young,stay simple
#include<iostream>
using namespace std;
const int MAXN=100005;
int lena,lenb;
int a[MAXN],b[MAXN];
int sa[MAXN],sb[MAXN];
bool vis[MAXN*10];
int main(){
cin>>lena>>lenb;
for(int i=1;i<=lena;i++){
cin>>a[i];
sa[i]=sa[i-1]+a[i];
}
for(int i=1;i<=lenb;i++){
cin>>b[i];
sb[i]=sb[i-1]+b[i];
}
for(int i=1;i<=lena;i++) vis[sa[i]]=1;
int ans=0;
for(int i=1;i<=lenb;i++) {
if(vis[sb[i]]) ans++;
}
cout<<ans<<endl;
return 0;
}
[CF] 950B Intercepted Message的更多相关文章
- 469 B. Intercepted Message
http://codeforces.com/problemset/problem/950/B Hacker Zhorik wants to decipher two secret messages h ...
- 题解 CF950B 【Intercepted Message】
题目链接 先吐槽一番:本宝宝好久没写过题解了...首先我们想一个贪心策咯.就是我们预处理出前缀和,然后一边扫过去,记录一个l1,l2和一个n1,n2.分别表示我们现在第一个数组切到l1,上一次切是在n ...
- 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)
剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用 ...
- ACM 第七天
水题 B - Minimum’s Revenge There is a graph of n vertices which are indexed from 1 to n. For any pair ...
- Apache Mina -2
我们可以了解到 mina是个异步通信框架,一般使用场景是服务端开发,长连接.异步通信使用mina是及其方便的.不多说,看例子. 本次mina 使用的例子是使用maven构建的,过程中需要用到的jar包 ...
- Codeforces Round #469 Div. 2 A B C D E
A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...
- Codeforces Round #469 Div. 2题解
A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...
- 深入理解netty---从偶现宕机看netty流量控制
一.业务背景 目前移动端的使用场景中会用到大量的消息推送,push消息可以帮助运营人员更高效地实现运营目标(比如给用户推送营销活动或者提醒APP新功能). 对于推送系统来说需要具备以下两个特性: 消息 ...
- java8中CompletableFuture的使用介绍
既然CompletableFuture类实现了CompletionStage接口,首先我们需要理解这个接口的契约.它代表了一个特定的计算的阶段,可以同步或者异步的被完成.你可以把它看成一个计算流水线上 ...
随机推荐
- poj3185//BFS随便切...
//poj 3185 2 //利用bit,通过位运算切换状态 ,然后BFS一下,轻易水过. 3 //说完好像很简单...是的,简单是简单,弱第一次以这种位运算姿势过题,太劲.膜思路 ORZ... 4 ...
- C语言-------指针函数与函数指针的区别
一. 在学习arm过程中发现这“指针函数”与“函数指针”容易搞错,所以今天,我自己想一次把它搞清楚,找了一些资料,首先它们之间的定义: 1.指针函数是指带指针的函数,即本质是一个函数.函数返回类型是某 ...
- python函数基础(3)
第1章 编码补充 1.1 字符编码对照表 1.2 编码特性 1.4 encode/decode第2章 集合 2.1 特点 2.2 [重点]作用:去重 2.3 常用操作 2.3.1 删除 2.3.2 交 ...
- 【ADO.NET】 使用通用数据库操作类Database (SQL Server)
一.Web.config配置 <connectionStrings> <add name="constr_name" connectionString=" ...
- vue_resource 使用说明
前几天用vue-resource调用接口,用post方式给后端,发现后端php接受不到数据,这好奇怪,最后发现提交给后端的时候 需要加一个参数 就是:emulateJSON : true 这句话的意思 ...
- Spring-bean(一)
配置形式:基于xml文件的方式:基于注解的方式 Bean的配置方式:通过全类名(反射),通过工厂方法(静态工厂方法&实例工厂方法),FactoryBean 依赖注入的方式:属性注入,构造器注入 ...
- python的与或非运算
真的很重要,栽了个跟头!!!(虽然以前好像知道...) print(True or False and False) print((True or False) and False) # True # ...
- 通过HTML 取得页面、屏幕、浏览器的高度宽度
一.介绍 1. 容器 一个页面的展示,从外到内的容器为:屏幕.浏览器以及页面本身. HTML元素展现在页面内,页面展现在浏览器内,而浏览器展现在屏幕内. 通过Js的一些对象可以获取这些容器的高度.宽度 ...
- UVM挑战及概述
UVM的调度也具有其独特的挑战,尤其是在调试的领域.其中的一些挑战如下: 1. Phase的管理:objections and synchronization 2. 线程调试 3. Tracing i ...
- Mac environment setting
java 7 jdk http://www.ifunmac.com/2013/04/mac-jdk-7/ http://blog.sina.com.cn/s/blog_6dce99b101016744 ...