Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pii = pair<int, int>;
- constexpr int N = 2e3 + 5;
- ll m, n, l = 0, r = n, mid;
- vector<pair<ll, int>> a, b;
- vector<tuple<int, int, int>> ans;
- void Solve()
- {
- cin >> m >> n;
- for (int i = 0, v; i < m; i++)
- cin >> v, a.emplace_back(v, i);
- for (int i = 0, v; i < n; i++)
- cin >> v, b.emplace_back(v, i);
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- 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--)
- {
- while(a[cur].first >= b[f].first)
- cur--;
- while (s >= 0 && b[s].first >= a[cur].first)
- s--;
- if (s >= 0 && b[s].first < a[cur].first && a[cur].first < b[f].first)
- ans.emplace_back(a[cur].second, b[s].second, b[f].second);
- }
- cout << ans.size() << endl;
- for (auto [a, b, c]: ans)
- cout << a + 1 << " " << b + 1 << " " << c + 1 << endl;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement