Advertisement
limimage

na eto bol'no smotret'

Sep 12th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define endl "\n"
  4. using namespace std;
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8.  
  9. constexpr int N = 2e3 + 5;
  10.  
  11.  
  12. ll m, n, l = 0, r = n, mid;
  13. vector<pair<ll, int>> a, b;
  14. vector<tuple<int, int, int>> ans;
  15.  
  16.  
  17. void Solve()
  18. {
  19. cin >> m >> n;
  20. for (int i = 0, v; i < m; i++)
  21. cin >> v, a.emplace_back(v, i);
  22. for (int i = 0, v; i < n; i++)
  23. cin >> v, b.emplace_back(v, i);
  24. sort(a.begin(), a.end());
  25. sort(b.begin(), b.end());
  26. for (int s = (b.size() - 1) / 2, f = b.size() - 1, cur = a.size() - 1; cur >= 0 && s >= 0 && f > (b.size() - 1) / 2; f--, cur--, s--)
  27. {
  28. while(a[cur].first >= b[f].first)
  29. cur--;
  30. while (s >= 0 && b[s].first >= a[cur].first)
  31. s--;
  32. if (s >= 0 && b[s].first < a[cur].first && a[cur].first < b[f].first)
  33. ans.emplace_back(a[cur].second, b[s].second, b[f].second);
  34. }
  35. cout << ans.size() << endl;
  36. for (auto [a, b, c]: ans)
  37. cout << a + 1 << " " << b + 1 << " " << c + 1 << endl;
  38. }
  39.  
  40. int main()
  41. {
  42. ios::sync_with_stdio(false);
  43. cin.tie(nullptr);
  44. cout.tie(nullptr);
  45. Solve();
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement