| 1 | #include<bits/stdc++.h> |
| 2 | using namespace std; |
| 3 | int main() { |
| 4 | /* |
| 5 | s (the amount of money Monica has), |
| 6 | n (the number of keyboard brands) and |
| 7 | m (the number of USB drive brands). |
| 8 | loop over the number of keyboard brands and the number of USB drive brands |
| 9 | then if the keyboard and usb is smaller than or equal the amount of money Monica has then |
| 10 | it will be equal to the maximum of the result before the equal sign and keyboard + usb |
| 11 | */ |
| 12 | int s, n, m, a, res = -1, keyboard[1001], usb[1001]; |
| 13 | |
| 14 | cin >> s >> n >> m; |
| 15 | for (int i = 0; i < n; i++)cin >> keyboard[i]; |
| 16 | for (int i = 0; i < m; i++)cin >> usb[i]; |
| 17 | |
| 18 | for (int i = 0; i < n; i++) { |
| 19 | for (int j = 0; j < m; j++) { |
| 20 | if (keyboard[i] + usb[j] <= s)res = max(res, keyboard[i] + usb[j]); |
| 21 | } |
| 22 | } |
| 23 | cout << res << endl; |
| 24 | return 0; |
| 25 | } |