CF950B.Intercepted Message
普及-
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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, m__i (here the total length of the blocks b__i, 1 + b__i, 2 + ... + b__i, m__i 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.
黑客卓里克想要破译他昨天截获的两条秘密消息。每条消息是由若干加密数据块组成的序列,每个数据块包含若干字节的信息。
卓里克知道,每条消息均是一个存档(archive),其中包含一个或多个文件。他还知道这些存档在网络中是如何传输的:若某存档包含 k 个文件,其大小(单位:字节)分别为 l1, l2, …, lk,则第 i 个文件会被分割为一个或多个数据块 bi,1, bi,2, …, bi,mi(此处所有块的总长度满足 bi,1+bi,2+⋯+bi,mi=li),随后所有数据块按文件在存档中的原始顺序依次在网络中传输。
卓里克推测这两条消息包含的是同一个存档,因为它们的总长度相等。然而,同一文件在两条消息中可能被以不同的方式分割成数据块。
现给出两条消息中各数据块的长度。请帮助卓里克判断:若他的推测正确,则该存档最多可能包含多少个文件?
输入格式
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 _x_1, _x_2, ..., x__n (1 ≤ x__i ≤ 106) — 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 ≤ 106) — 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 ≤ 106.
第一行包含两个整数 n、m(1≤n,m≤105)—— 分别表示第一条和第二条消息中的分块数量。
第二行包含 n 个整数 x1, x2, …, xn(1≤xi≤106)—— 表示构成第一条消息的各分块长度。
第三行包含 m 个整数 y1, y2, …, ym(1≤yi≤106)—— 表示构成第二条消息的各分块长度。
保证 x1+⋯+xn=y1+⋯+ym,且 x1+⋯+xn≤106。
输出格式
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.
在第一个例子中,压缩包中文件的最大数量为 3。例如,压缩包中可能包含三个文件,其大小分别为 2+5=7、15=3+1+11=8+2+4+1 和 4+4=8。
在第二个例子中,压缩包中可能包含两个文件,其大小分别为 1 和 110=10+100=100+10。注意,压缩包在网络中传输时会保持文件的顺序,因此我们不能认为其中包含三个大小分别为 1、10 和 100 的文件。
在第三个例子中,唯一可能的情况是压缩包中仅包含一个大小为 4 的文件。
输入解题思路,AI测评打分。不知道怎么写?