Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- #include<math.h>
- #include<algorithm>
- #include <utility>
- #pragma once
- long long mm, nn;
- std ::vector<std ::pair<int, int>> aa, bb;
- long long ans[100000][3], otv = 0;
- bool podh(long long now) {
- long long col = 0 , ii = 0;
- while (ii < mm) {
- if (aa[ii].first > bb[col].first && aa[ii].first < bb[nn - now + col].first) {
- ++col;
- if (col == now) {
- return 1;
- }
- }
- ++ii;
- }
- return 0;
- }
- int main() {
- std ::cin >> mm >> nn;
- for (long long ii = 0; ii < mm; ++ii) {
- long long now;
- std ::cin >> now;
- aa.push_back(std ::make_pair(now, ii + 1));
- }
- for (long long ii = 0; ii < nn; ++ii) {
- long long now;
- std ::cin >> now;
- bb.push_back(std ::make_pair(now, ii + 1));
- }
- std ::sort(aa.begin(), aa.end());
- std ::sort(bb.begin(), bb.end());
- long long lhs = -1, rhs = std ::min(nn / 2, mm), mid;
- while (rhs > lhs + 1) {
- mid = (lhs + rhs) / 2;
- if (podh(mid)) {
- lhs = mid;
- } else {
- rhs = mid;
- }
- }
- if (!podh(rhs)) {
- --rhs;
- }
- if (rhs == -1) {
- std ::cout << 0;
- return 0;
- }
- long long col = 0 , ii = 0;
- while (ii < mm) {
- if (col == rhs) {
- break;
- }
- if (aa[ii].first > bb[col].first && aa[ii].first < bb[nn - rhs + col].first) {
- ans[col][0] = aa[ii].second;
- ans[col][1] = bb[col].second;
- ans[col][2] = bb[nn - rhs + col].second;
- ++col;
- }
- ++ii;
- }
- std ::cout << rhs << std ::endl;
- for (long long ii = 0; ii < rhs; ++ii) {
- std ::cout << ans[ii][0] << " " << ans[ii][1] << " " << ans[ii][2] << std ::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement