Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int maxn = 3e5 + 10;
- int main(){
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<pair<int, int> > rank(n), type(n);
- for(int i = 0; i < n; i++) {
- cin >> rank[i].first;
- rank[i].second = i;
- }
- for(int i = 0; i < n; i++) {
- cin >> type[i].first;
- type[i].second = i;
- }
- vector<pair<int, int> > ans;
- while(true) {
- int min_difference = 2e9;
- int idx = -1;
- int i1 = -1, i2 = -1;
- for(int i = 0; i + 1 < rank.size(); i++) {
- if(type[i].first != type[i + 1].first) {
- if(abs(rank[i].first - rank[i + 1].first) < min_difference) {
- min_difference = abs(rank[i].first - rank[i + 1].first);
- idx = i;
- i1 = rank[i].second + 1;
- i2 = rank[i + 1].second + 1;
- }
- }
- }
- if(idx == -1) {
- break;
- }
- ans.push_back(make_pair(i1, i2));
- rank.erase(rank.begin() + idx);
- rank.erase(rank.begin() + idx);
- type.erase(type.begin() + idx);
- type.erase(type.begin() + idx);
- }
- cout << (int) ans.size() << "\n";
- for(int i = 0; i < ans.size(); i++) {
- cout << ans[i].first << " " << ans[i].second << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement