-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path404-double-sort.cpp
More file actions
46 lines (45 loc) · 1.17 KB
/
Copy path404-double-sort.cpp
File metadata and controls
46 lines (45 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Double Sort [1681C]
* Problem: https://codeforces.com/problemset/problem/1681/C
* Verdict: ACCEPTED Solved: 2025-03-19
* Language: C++17 (GCC 7-32)
* Runtime: 124 ms Memory: 0 KB
* Tags: implementation, sortings
* Author: BidoTeima
* Source: https://codeforces.com/contest/1681/submission/311395844
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n],b[n];
for(auto&i:a)cin>>i;
for(auto&i:b)cin>>i;
vector<pair<int,int>>ans;
for(int j = 0; j < n; j++){
for(int i = 0; i + 1 < n; i++){
if(a[i]>a[i+1]||b[i]>b[i+1]){
ans.push_back({i,i+1});
swap(a[i],a[i+1]);
swap(b[i],b[i+1]);
}
}
}
if(!is_sorted(a,a+n) || !is_sorted(b,b+n)){
cout<<"-1\n";
}else{
cout<<(int)ans.size()<<'\n';
for(auto&p:ans)cout<<p.first+1<<' '<<p.second+1<<'\n';
}
}
return 0;
}