Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. #include<math.h>
  4. #include<algorithm>
  5. #include <utility>
  6. #pragma once
  7. long long mm, nn;
  8. std ::vector<std ::pair<int, int>> aa, bb;
  9. long long ans[100000][3], otv = 0;
  10. bool podh(long long now) {
  11. long long col = 0 , ii = 0;
  12. while (ii < mm) {
  13. if (aa[ii].first > bb[col].first && aa[ii].first < bb[nn - now + col].first) {
  14. ++col;
  15. if (col == now) {
  16. return 1;
  17. }
  18. }
  19. ++ii;
  20. }
  21. return 0;
  22. }
  23.  
  24. int main() {
  25. std ::cin >> mm >> nn;
  26. for (long long ii = 0; ii < mm; ++ii) {
  27. long long now;
  28. std ::cin >> now;
  29. aa.push_back(std ::make_pair(now, ii + 1));
  30. }
  31. for (long long ii = 0; ii < nn; ++ii) {
  32. long long now;
  33. std ::cin >> now;
  34. bb.push_back(std ::make_pair(now, ii + 1));
  35. }
  36. std ::sort(aa.begin(), aa.end());
  37. std ::sort(bb.begin(), bb.end());
  38. long long lhs = -1, rhs = std ::min(nn / 2, mm), mid;
  39. while (rhs > lhs + 1) {
  40. mid = (lhs + rhs) / 2;
  41. if (podh(mid)) {
  42. lhs = mid;
  43. } else {
  44. rhs = mid;
  45. }
  46. }
  47. if (!podh(rhs)) {
  48. --rhs;
  49. }
  50. if (rhs == -1) {
  51. std ::cout << 0;
  52. return 0;
  53. }
  54. long long col = 0 , ii = 0;
  55. while (ii < mm) {
  56. if (col == rhs) {
  57. break;
  58. }
  59. if (aa[ii].first > bb[col].first && aa[ii].first < bb[nn - rhs + col].first) {
  60. ans[col][0] = aa[ii].second;
  61. ans[col][1] = bb[col].second;
  62. ans[col][2] = bb[nn - rhs + col].second;
  63. ++col;
  64. }
  65. ++ii;
  66. }
  67. std ::cout << rhs << std ::endl;
  68. for (long long ii = 0; ii < rhs; ++ii) {
  69. std ::cout << ans[ii][0] << " " << ans[ii][1] << " " << ans[ii][2] << std ::endl;
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement