/****************************************
* 2012/06/25 *
* AOJ Volume11 1153 Equal Totaol Score *
* crane *
*****************************************/
#include<iostream>
using namespace std;
#define MAX_N 100
#define MAX_M 100
int n_field[MAX_N];
int m_field[MAX_M];
int n_c[MAX_N]; //コピー
int m_c[MAX_M]; //コピー
int n; //太郎のカード
int m; //花子のカード
int main(){
while(cin >> n >> m, (n||m)){
int sn=0, sm=0;
for(int i=0; i<n; i++){
cin >> n_field[i];
sn += n_field[i]; //合計n側
}
for(int i=0; i<m; i++){
cin >> m_field[i];
sm += m_field[i]; //合計m側
}
int li=0, lj=0, l_sum=1000;
int c_sn, c_sm; //合計のコピー
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
c_sn = sn;
c_sm = sm;
c_sn = c_sn - n_field[i] + m_field[j];
c_sm = c_sm - m_field[j] + n_field[i];
if(c_sn == c_sm)
if(n_field[i] + m_field[j] <= l_sum){
l_sum = n_field[i] + m_field[j];
li = n_field[i];
lj = m_field[j];
}
}
}
if(l_sum == 1000)
cout << -1 << endl;
else
cout << li << " " << lj << endl;
}
return 0;
}
0 件のコメント:
コメントを投稿