fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main (void)
  7. {
  8. vector <int> a = {1, 2, 3, 4, 5, 6};
  9. vector <int> b = {1, 2, 3, 5, 5, 6};
  10. int X = 6;
  11.  
  12. int i = 0;
  13. int j = b.size () - 1;
  14.  
  15. while (i < (int) a.size())
  16. {
  17. while (a[i] + b[j] > X && j > 0)
  18. j--;
  19. if (a[i] + b[j] == X)
  20. cout << i << " " << j << endl;
  21. i++;
  22. }
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
0 4
2 2
3 1
4 0