#include<iostream>
#include<algorithm>
#include<vector>
#define endl '\n'
using namespace std;
int n,s,p[1005];
pair<int,int> m[1005];
bool cmp(pair<int,int> a, pair<int,int> b)
{
return a.first>b.first;
}
vector< pair<int,int> > v;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>s;
for(int i=1;i<=n;i++){
cin>>m[i].first;
m[i].second=i;
}
sort(m+1,m+n+1,cmp);
int t;
for(int i=1;i<=n;i++)
{
t=m[i].second-p[m[i].second];
for(int j=m[i].second+1;j<=n-i;j++) p[j]++;
for(int j=1;j<=n-i;j++)
{
v.push_back({j,j+1});
//cout<<j<<" "<<j+1<<endl;
}
for(int j=t+1;j<=n-i+1;j++)
{
v.push_back({j,j-1});
//cout<<j<<" "<<j-1<<endl;
}
for(int j=t-2;j>=1;j--)
{
v.push_back({j,j+1});
//cout<<j<<" "<<j+1<<endl;
}
}
cout<<v.size()<<endl;
for(int i=0;i<v.size();i++)
{
cout<<v[i].first<<" "<<v[i].second<<endl;
}
}
Compilation message
xorsort.cpp: In function 'int main()':
xorsort.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Not sorted |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Not sorted |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Not sorted |
2 |
Halted |
0 ms |
0 KB |
- |