-
Notifications
You must be signed in to change notification settings - Fork 2
/
CF 384B Multitasking.cpp
47 lines (47 loc) · 1.21 KB
/
CF 384B Multitasking.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
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <set>
using namespace std;
int main()
{
int n,m,k;
cin>>n>>m>>k;
set<pair<int,int>>v;
while(n--){
int a[m]={0}, sz=m;
for(int i=0; i<m; i++)cin>>a[i];
if(k==0){
int i, j, key;
for(j = 1; j < sz; j++){
key = a[j];
i = j - 1;
while(i >= 0 && a[i] > key){
a[i+1] = a[i];
v.insert(make_pair(j+1,i+1));
i--;
}
a[i+1] = key;
}
}
else{
int i, j, key;
for(j=1; j<sz; j++){
key=a[j];
i=j-1;
while(i >= 0 && a[i] < key){
a[i+1] = a[i];
v.insert(make_pair(j+1,i+1));
i--;
}
a[i+1] = key;
}
}
}
cout<<v.size()<<endl;
set<pair<int,int>>::iterator it;
for(it=v.begin(); it!=v.end(); it++){
if(k==0)
cout<<min(it->first,it->second)<<" "<<max(it->first,it->second)<<endl;
if(k==1)
cout<<max(it->first,it->second)<<" "<<min(it->first,it->second)<<endl;
}
}