Ուղարկել | Բոլոր լուծումները | Լավագույն լուծումները | Վերադառնալ ցուցակին |
ACM_0189 - ELECTRICITY |
You are managing a power network for a programming competition and you have to connect a lot of computers to the power supply. Unfortunately, there are two standards for electrical plug and socket: A and B. These standards are incompatible, so the plug of standard A can only be plugged in the socket of standard A and the plug of standard B can only be plugged in the socket of standard B.
In the main competition hall, there is exactly one main socket of type A. Every computer that will be used in this programming competition has one plug of type A. Thereby only one computer can be connected directly to the main socket. But you have a number of power strips of two types.
• Power strips of the first type have one plug of type A and several sockets of type B.
• Power strips of the second type have one plug of type B and several sockets of type A.
All the power strips are very powerful and can withstand any load. So you can create a power network by connecting one power strip of the first type to the main socket, then some power strips of the second type to this power strip of the first type, etc. At the end you will get several available sockets of type A for computers.
Your task is to find the maximum number of computers that can be connected to the power network, using available power strips.
Possible solution for the first example. Possible solution for the second example.
Input
The first line of input file contains two integer numbersnandm— the number of power strips of the first and the second type (0≤n;m≤100000).
The second line containsninteger numbers ai — the number of sockets on the power strips of the first type (1≤ai ≤1000).
The second line containsminteger numbers bi — the number of sockets on the power strips of the second type (1≤bi ≤1000).
Output
Output the maximum number of computers that can be connected to the power network.
Examples
№ |
stdin |
stdout |
1 |
3 2 3 2 1 2 3 |
5 |
2 |
2 3 2 2 2 3 1 |
5 |
Ավելացրեց. | Հրանտ Հովհաննիսյան |
Ամսաթիվ. | 2014-04-09 |
Ժամանակի սահմանափակումը. | 1s |
Ծրագրի տեքստի սահմանափակումը. | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Լեզուներ. | Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE |
Աղբյուրը. | Northern QF 2012.E |