fork download
  1. struct Pair{int first;int second;};
  2.  
  3. l(a,n,p)int*a;{return n?n<0?a[-n]<p?(((a[-n]^=*a),*a^=a[-n]),a[-n]^=*a),l(a+1,~n,p)+1:l(a,n+1,p):*a<p?l(a+1,n-1,p)+1:l(a,1-n,p):-1;}
  4. struct Pair f(a,n,p)int*a;{struct Pair r={l(a,n,p),l(a,n,p+1)};return r;}
  5.  
  6. #include <stdio.h>
  7. main() {
  8. int n, p, i;
  9. scanf("%d%d", &n, &p);
  10. int a[n];
  11. for(i=0; i<n; i++) scanf("%d", &a[i]);
  12. struct Pair r = f(a, n, p);
  13. for(i=0; i<n; i++) printf("%d ", a[i]);
  14. printf("\n%d,%d\n", r.first, r.second);
  15. }
  16.  
Success #stdin #stdout 0s 1836KB
stdin
19 8
9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9
stdout
7 6 7 6 5 4 3 2 1 0 1 2 3 4 5 8 8 9 9 
14,16