This page is still under construction.

Parts of this page are still being built. What you see may change.

Domino

Interview

Time limit1sMemory limit128 MB

Summary
Choose the smallest chain from the first to the last domino where each kept tile is taller than the distance to the next kept tile.
Level

Medium6 of 10

Topics
Greedy, Prefix sum, Binary search
Solved
No attempts yet

Problem

Jaś is setting up dominoes, but not in the traditional way; he plays by toppling one tile after another. His tiles all have different heights. He placed nn dominoes in a row so that toppling any tile makes the next tile in the row topple as well. A tile topples the next one exactly when the height of the toppling tile is greater than the distance between them. Jaś wants to know the maximum number of unnecessary tiles he can remove from the row so that toppling the first tile still makes the last tile topple (through the intermediate tiles falling in turn). Jaś may not change the positions of the tiles.

Input

The first line contains the number of tiles nn (1≤n≤1061 \le n \le 10^6). The second line contains nn integers w1,w2,…,wnw_1, w_2, \ldots, w_n (1≤wi≤1091 \le w_i \le 10^9), where wiw_i is the height of the ii-th tile in the row. The third line contains n−1n-1 integers x1,x2,…,xn−1x_1, x_2, \ldots, x_{n-1} (1≤xi≤1091 \le x_i \le 10^9), where xix_i is the distance between the ii-th and the (i+1)(i+1)-th tile. In the initial arrangement each tile can topple its immediate neighbor, that is wi>xiw_i > x_i for every i<ni < n.

Output

Print a single integer: the maximum number of tiles that can be removed from the row.

Examples1

  1. Example 1

    Input
    5
    4 2 3 2 1
    2 1 1 1
    
    Expected output
    2