Under construction

Still being built. Things may change

Putnik

Time limit2sMemory limit1024 MB

Summary
Choose the stations where the express Putnik stops so that the total number of passengers who switch to it is as large as possible.
Level

Medium6 of 10

Topics
Dynamic programming, Prefix sum
Solved
No attempts yet

Statement

Huge numbers of people ride commuter trains every day. This problem covers the line from the station "Zhilye Mytishchi" (ZhM for short) to the station "Bolshaya Tsentralnaya" (BTs for short). The line has n+1n + 1 stations. Station ZhM has number nn, and station BTs has number 00. Stations ii and i+1i + 1 are connected by a track segment for every ii, and no other pairs of stations are connected. Every train starts at ZhM and goes to BTs. Station ii has cic_i passengers each day who want to reach BTs, and there are no other passengers. An ordinary train needs eie_i minutes to cover the segment between station ii and station i−1i - 1. Passengers board instantly. The board of directors has decided to run an express from the ZhM depot to BTs. The new train is called "Putnik". Each segment has its own track for Putnik, and it takes Putnik pip_i minutes to travel from station ii to station i−1i - 1. As often happens in practice, pip_i can be less than eie_i or greater than it. Putnik is an express, so each stop takes one minute for the attendants to give a safety briefing on high-speed trains. Passengers follow a simple rule. They switch to the new express only if it makes their travel time from their station to station 00 strictly smaller. A passenger boards Putnik at the very start of its stop, so the passenger spends that minute on the greeting and the briefing. The board wants to maximize the number of people who ride the new train. Choose the stations where the express stops so that as many people as possible ride it. Putnik starts from the ZhM depot, but it does not have to stop at ZhM.

Input

The first line contains nn (1≤n≤10001 \leq n \leq 1000), the number of segments between ZhM and BTs. The second line contains nn integers eie_i (1≤ei≤1091 \leq e_i \leq 10^9), the minutes an ordinary train needs to travel from station ii to station i−1i - 1. The third line contains nn integers cic_i (1≤ci≤1091 \leq c_i \leq 10^9), the number of people each day who try to get from station ii to station 00. The fourth line contains nn integers pip_i (1≤pi≤1091 \leq p_i \leq 10^9), the minutes Putnik needs to travel the segment between stations ii and i−1i - 1.

Output

Print one integer, the maximum possible number of passengers who ride the new express.

Hints

In the first sample, Putnik reaches BTs one minute faster than the ordinary train if it makes no stops. However, if it stops anywhere, that advantage disappears and nobody rides the new train. In the second sample, the express must stop at stations 22 and 33. It cannot stop at station 11, because that would make the trips from station 22 unprofitable.

Examples2

  1. Example 1

    Input
    2
    1 2
    2 2
    1 1
    
    Expected output
    0
    
  2. Example 2

    Input
    3
    3 2 30
    10 100 1
    1 2 10
    
    Expected output
    101