A11573 | Intercepted Message
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $l_{1},l_{2},...,l_{k}$ bytes, then the $i$ -th file is split to one or more blocks $b_{i,1},b_{i,2},...,b_{i,mi}$ (here the total length of the blocks $b_{i,1}+b_{i,2}+...+b_{i,mi}$ is equal to the length of the file $l_{i}$ ), 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.
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 $l_{1},l_{2},...,l_{k}$ bytes, then the $i$ -th file is split to one or more blocks $b_{i,1},b_{i,2},...,b_{i,mi}$ (here the total length of the blocks $b_{i,1}+b_{i,2}+...+b_{i,mi}$ is equal to the length of the file $l_{i}$ ), 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.
输入格式
The first line contains two integers $n$ , $m$ ( $1<=n,m<=10^{5}$ ) — the number of blocks in the first and in the second messages.
The second line contains $n$ integers $x_{1},x_{2},...,x_{n}$ ( $1<=x_{i}<=10^{6}$ ) — the length of the blocks that form the first message.
The third line contains $m$ integers $y_{1},y_{2},...,y_{m}$ ( $1<=y_{i}<=10^{6}$ ) — the length of the blocks that form the second message.
It is guaranteed that $x_{1}+...+x_{n}=y_{1}+...+y_{m}$ . Also, it is guaranteed that $x_{1}+...+x_{n}<=10^{6}$ .
The second line contains $n$ integers $x_{1},x_{2},...,x_{n}$ ( $1<=x_{i}<=10^{6}$ ) — the length of the blocks that form the first message.
The third line contains $m$ integers $y_{1},y_{2},...,y_{m}$ ( $1<=y_{i}<=10^{6}$ ) — the length of the blocks that form the second message.
It is guaranteed that $x_{1}+...+x_{n}=y_{1}+...+y_{m}$ . Also, it is guaranteed that $x_{1}+...+x_{n}<=10^{6}$ .
输出格式
Print the maximum number of files the intercepted array could consist of.
输入输出样例
输入 #1
7 6 2 5 3 1 11 4 4 7 8 2 4 1 8
输出 #1
3
输入 #2
3 3 1 10 100 1 100 10
输出 #2
2
输入 #3
1 4 4 1 1 1 1
输出 #3
1
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted