-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj1153.cpp
More file actions
65 lines (58 loc) · 1.06 KB
/
aoj1153.cpp
File metadata and controls
65 lines (58 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
int main() {
int n, m;
while(cin >> n >> m, n|m) {
int t[n], h[m];
int sum_t = 0, sum_h = 0;
for(int i=0; i<n; i++) {
cin >> t[i];
sum_t += t[i];
}
for(int i=0; i<m; i++) {
cin >> h[i];
sum_h += h[i];
}
int t2[n], h2[m];
for(int i=0; i<n; i++)
t2[i] = sum_t - t[i];
for(int i=0; i<m; i++)
h2[i] = sum_h - h[i];
int cnt = 1000 * 10000;
int taro = 0, hana = 0;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(t2[i] + h[j] == h2[j] + t[i]) {
int just = t2[i] + h[j];
if(cnt > just) {
cnt = just;
taro = t[i];
hana = h[j];
}
}
}
}
if(taro || hana)
cout << taro << ' ' << hana << endl;
else
cout << "-1" << endl;
}
return 0;
}