950B.md (2893B)
1 Source: https://codeforces.com/problemset/problem/950/B 2 3 B. Intercepted Message 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 512 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 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. 24 25 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. 26 27 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. 28 29 Input 30 31 The first line contains two integers *n*, *m* (1 ≤ *n*, *m* ≤ 105) — the number of blocks in the first and in the second messages. 32 33 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. 34 35 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. 36 37 It is guaranteed that *x*1 + ... + *x**n* = *y*1 + ... + *y**m*. Also, it is guaranteed that *x*1 + ... + *x**n* ≤ 106. 38 39 Output 40 41 Print the maximum number of files the intercepted array could consist of. 42 43 Examples 44 45 Input 46 47 ``` 48 7 6 49 2 5 3 1 11 4 4 50 7 8 2 4 1 8 51 ``` 52 53 Output 54 55 ``` 56 3 57 ``` 58 59 Input 60 61 ``` 62 3 3 63 1 10 100 64 1 100 10 65 ``` 66 67 Output 68 69 ``` 70 2 71 ``` 72 73 Input 74 75 ``` 76 1 4 77 4 78 1 1 1 1 79 ``` 80 81 Output 82 83 ``` 84 1 85 ``` 86 87 Note 88 89 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. 90 91 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. 92 93 In the third example the only possibility is that the archive contains a single file of size 4.