Giter Site home page Giter Site logo

m2003's Introduction

m2003 Corona and Masks

Problem Statement

There are N pharmacies that sell masks. The i-th pharmacy is located at Xi on the number line and have Ai masks initially. In each second, all pharmacies will sell 1 mask (if the pharmacy still have stock). Corona's home is located at position 0 and she can make up to two round trips to visit the pharmacies. Each round trip is defined as traveling from her home to a location on the number line in a single direction, and then return to home in the opposite direction. Corona can travel 1 unit per second. It takes no time for her to buy all the masks available at a pharmacy which she passes through (or arrives at).

How many masks can Corona possibly buy?

Input

The first line contains an integer N.
The second line contains N integers X1, X2,..., XN.
Xi ≠ 0 for all 1 ≤ i ≤ N and Xi < Xi+1 for all 1 ≤ i ≤ N.
The third line contains N integers A1, A2,..., AN.

Output

Output a single integer: the maximum possible number of masks Corona can buy.

Sample Tests

Input 1

4
-2 -1 5 15
10 5 20 8

Output 1

23

Input 2

2
-100 100
1 1

Output 2

0

Subtasks

For all cases: 1 ≤ Ai ≤ 106

# Points Constraints
1 10 1 ≤ N ≤ 100
1 ≤ Xi ≤ 1000
2 20 1 ≤ N ≤ 4
-100 ≤ Xi ≤ 100
3 25 1 ≤ N ≤ 100
-1000 ≤ Xi ≤ 1000
4 45 1 ≤ N ≤ 100000
-106 ≤ Xi ≤ 106

Original version from HKOI Online Judge
Source: Hong Kong Olympiad in Informatics Organizing Committee. This problem is under the Creative Commons Attribution-ShareAlike 4.0 International licence.

m2003's People

Contributors

miyagi-sensei avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.