259. Printed PR
time limit per test: 0.25
sec.
memory limit per test: 65536
KB
input: standard
output: standard
Small PRagency 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 ith leaflet the printer needs T_{i} 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 L_{i} minutes to deliver ith 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.
Input
The first line contains a number of leaflets  integer number N (1 <= N <= 100). The second line contains N integer numbers T_{i} (1 <= i <= N). Third line contains N integer numbers L_{i} (1 <= i <= N). You can assume that 1 <= T_{i}, L_{i} <= 1000.
Output
You should output only one number  the answer for the problem.
Sample test(s)
Input
2
2 1
2 1
Output
4
Author:  Ilya V. Elterman

Resource:  Saratov SU Contest: Golden Fall 2004

Date:  October 2, 2004

Server time: 20170926 22:08:38  Online Contester Team © 2002  2016. All rights reserved. 

