Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************
- *** Problem : Sereja and Sorting 2
- *** Author : Kaidul Islam
- *** E-mail : [email protected]
- *** Blog : http://kaidul.efireit.com
- ****************************************************/
- #include <bits/stdc++.h>
- using namespace std;
- #define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
- #define repl(i,n) for(__typeof(n) i=1; i<=(n); i++)
- #define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
- /** function **/
- #define SDi(x) sf("%d", &x)
- #define SDs(x) sf("%s", x)
- #define pf printf
- #define print(x) pf("%d ", x)
- #define println(x) pf("%d\n", x)
- #define sf scanf
- #define READ(f) freopen(f, "r", stdin)
- /** Implementation **/
- #define Max 20000
- int a[Max];
- int start[Max];
- int end[Max];
- int main() {
- int Q = 0;
- int n;
- SDi(n);
- repl(i, n) SDi(a[i]);
- repl(i, n) {
- int k = i;
- FOR(j, i + 1, n) if(a[k] > a[j]) k = j;
- if (k != i) {
- reverse(a + i, a + k + 1);
- Q++;
- start[Q] = i;
- end[Q] = k;
- }
- }
- println(Q);
- repl(i, Q) print(start[i]), println(end[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment