-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy path1681C-DoubleSort.cpp
37 lines (31 loc) · 1.15 KB
/
1681C-DoubleSort.cpp
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
#include <cstdio>
#include <vector>
#include <algorithm>
int main(){
long t; scanf("%ld", &t);
while(t--){
long n; scanf("%ld", &n);
std::vector<std::pair<long, long> > va(n);
std::vector<long> wa(n);
for(long p = 0; p < n; p++){scanf("%ld", &va[p].first); va[p].second = p; wa[p] = va[p].first;}
sort(va.begin(), va.end());
std::vector<long> vb(n); for(long p = 0; p < n; p++){scanf("%ld", &vb[p]);}
bool possible(true);
for(long p = 1; possible && p < n; p++){
if(vb[va[p - 1].second] > vb[va[p].second]){possible = false;}
}
if(!possible){puts("-1"); continue;}
std::vector<std::pair<long, long> > s;
for(long p = 0; p < n; p++){
for(long q = 1; q < n; q++){
if(wa[q - 1] <= wa[q]){continue;}
long tmp = wa[q - 1]; wa[q - 1] = wa[q]; wa[q] = tmp;
s.push_back(std::make_pair(q, q + 1));
}
}
printf("%ld\n", s.size());
if(s.empty()){continue;}
for(long p = 0; p < s.size(); p++){printf("%ld %ld\n", s[p].first, s[p].second);}
puts("");
}
}