934A.md (1823B)
1 Source: https://codeforces.com/problemset/problem/934/A 2 3 A. A Compatible Pair 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. 22 23 Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1, *a*2, ..., *a**n*, and Banban's have brightness *b*1, *b*2, ..., *b**m* respectively. 24 25 Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns. 26 27 Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible. 28 29 You are asked to find the brightness of the chosen pair if both of them choose optimally. 30 31 Input 32 33 The first line contains two space-separated integers *n* and *m* (2 ≤ *n*, *m* ≤ 50). 34 35 The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n*. 36 37 The third line contains *m* space-separated integers *b*1, *b*2, ..., *b**m*. 38 39 All the integers range from - 109 to 109. 40 41 Output 42 43 Print a single integer — the brightness of the chosen pair. 44 45 Examples 46 47 Input 48 49 ``` 50 2 2 51 20 18 52 2 14 53 ``` 54 55 Output 56 57 ``` 58 252 59 ``` 60 61 Input 62 63 ``` 64 5 3 65 -1 0 1 2 3 66 -1 0 1 67 ``` 68 69 Output 70 71 ``` 72 2 73 ``` 74 75 Note 76 77 In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself. 78 79 In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.