fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int n,m,x;
  8. cin>>n>>m;
  9. map<int,int>a,b;
  10. for(int i =0;i<n;i++) cin>>x ,a[x] = i;
  11.  
  12. for(int i =0;i<m;i++) cin>>x, b[x] = i;
  13.  
  14. for (auto i = a.begin(); i != a.end(); i++)
  15. cout << i->first << " " << i->second
  16. << endl;
  17. bool check = false;
  18.  
  19. set<int> st;
  20. auto i = begin(a);
  21. auto j = --end(a);
  22. while(st.size()<n+m-1) {
  23. check = !check;
  24. auto x = check ? i : j;
  25.  
  26. for(auto y : b){
  27. auto it = st.insert(x->first+y.first);
  28. if(it.second) {
  29. //cout<<x->second<<" "<<y.second<<endl;
  30. }
  31.  
  32. if(st.size() == n+m-1)break;
  33. }
  34.  
  35. if(check) ++i ;
  36. else --j;
  37. }
  38.  
  39.  
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 4260KB
stdin
3 2
10 1 100
4 3
stdout
1      1
10      0
100      2