码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 950B Intercepted Message

时间:2018-03-10 14:06:02      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:blog   more   cat   determine   for   only   use   correct   col   

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 nm (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 + ... + ymAlso, it is guaranteed that x1 + ... + xn ≤ 106.

Output

Print the maximum number of files the intercepted array could consist of.

Example

Input
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8
Output
3
Input
3 3
1 10 100
1 100 10
Output
2
Input
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 1and 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.

 

 1 #include<iostream>
 2 using namespace std;
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<vector>
 6 vector<int> a,b;
 7 int main(){
 8     int n,m;
 9     scanf("%d%d",&n,&m);
10     int p;
11     for(int i = 0; i< n;i++){
12         scanf("%d",&p);
13         a.push_back(p);
14     }
15     for(int i = 0;i < m;i++){
16         scanf("%d",&p);
17         b.push_back(p);
18     }
19     typedef long long ll;
20     ll s1 = 0, s2 = 0;
21     int i = 0,j = 0;
22     int ans = 0;
23     while(i<n||j<m){
24         if(i>=n||s1>s2)
25             s2+=b[j++];
26         else
27             s1+=a[i++];
28         if(s1==s2){
29             s1=s2=0;
30             ans+=1;
31         }
32     }
33     printf("%d",ans);
34     return 0;
35 }

 

CodeForces 950B Intercepted Message

标签:blog   more   cat   determine   for   only   use   correct   col   

原文地址:https://www.cnblogs.com/xfww/p/8538565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!