time limit per test: 0.25 sec. memory limit per test: 65536 KB
input: standard output: standard
Small PR-agency got an order to print a very big lot of agitational materials. Agency should print and deliver N leaflets. Agency is very small and has only one printer, but it can print any leaflet. Leaflets can be different, so it is possible that times of printing of leaflets will differ. To print i-th leaflet the printer needs Ti minutes. When leaflet is printed, it should be immediately delivered to its addressee. The agency has unlimited number of couriers, so the courier gets the leaflet as soon as it printed and goes to the addressee. It takes Li minutes to deliver i-th leaflet. You were hired by agency to calculate the minimal time required to finish the job (this is an interval of time from the beginning of printing to the moment when the last leaflet is delivered), considering that the leaflets can be printed in any order.
The first line contains a number of leaflets - integer number N (1 <= N <= 100). The second line contains N integer numbers Ti (1 <= i <= N). Third line contains N integer numbers Li (1 <= i <= N). You can assume that 1 <= Ti, Li <= 1000.
You should output only one number - the answer for the problem.
2 2 1 2 1
Ilya V. Elterman
Saratov SU Contest: Golden Fall 2004
October 2, 2004
Codeforces (c) Copyright 2010-2021 Mike Mirzayanov