fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. pair<int,int> solve(vector<int>& A, vector<int>& B) {
  5. pair<int,int> result;
  6. int minimumAbsoluteValue = INT_MAX;
  7. for(int i = 0; i < A.size(); i++) {
  8. for(int j = 0; j < B.size(); j++) {
  9. if(minimumAbsoluteValue > abs(A[i] + B[j])) {
  10. minimumAbsoluteValue = abs(A[i] + B[j]);
  11. result.first = i + 1;
  12. result.second = j + 1;
  13. }
  14. }
  15. }
  16. return result;
  17. }
  18.  
  19. int main() {
  20. int m, n; cin >> m >> n;
  21. vector<int> A(m);
  22. vector<int> B(n);
  23.  
  24. for(int& x : A) cin >> x;
  25. for(int& x : B) cin >> x;
  26.  
  27. pair<int, int> res = solve(A, B);
  28. cout << res.first << " " << res.second;
  29.  
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5284KB
stdin
4 5 
1 8 2 9 
-5 -6 3 -7 -4
stdout
2 4