CF771E.Bear and Rectangle Strips

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Limak has a grid that consists of 22 rows and nn columns. The jj -th cell in the ii -th row contains an integer ti,jt_{i,j} which can be positive, negative or zero.

A non-empty rectangle of cells is called nice if and only if the sum of numbers in its cells is equal to 00 .

Limak wants to choose some nice rectangles and give them to his friends, as gifts. No two chosen rectangles should share a cell. What is the maximum possible number of nice rectangles Limak can choose?

输入格式

The first line of the input contains an integer nn ( 1<=n<=3000001<=n<=300000 ) — the number of columns in the grid.

The next two lines contain numbers in the grid. The ii -th of those two lines contains nn integers ti,1,ti,2,...,ti,nt_{i,1},t_{i,2},...,t_{i,n} ( 109<=ti,j<=109-10^{9}<=t_{i,j}<=10^{9} ).

输出格式

Print one integer, denoting the maximum possible number of cell-disjoint nice rectangles.

输入输出样例

  • 输入#1

    6
    70 70 70 70 70 -15
    90 -60 -30 30 -30 15
    

    输出#1

    3
    
  • 输入#2

    4
    0 -1 0 0
    0 0 1 0
    

    输出#2

    6
    
  • 输入#3

    3
    1000000000 999999999 -1000000000
    999999999 -1000000000 -999999998
    

    输出#3

    1
    

说明/提示

In the first sample, there are four nice rectangles:

Limak can't choose all of them because they are not disjoint. He should take three nice rectangles: those denoted as blue frames on the drawings.

In the second sample, it's optimal to choose six nice rectangles, each consisting of one cell with a number 00 .

In the third sample, the only nice rectangle is the whole grid — the sum of all numbers is 00 . Clearly, Limak can choose at most one nice rectangle, so the answer is 11 .

首页