fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, x, i, me, idm;
  6. long long at=0, c[100005];
  7. scanf(" %d %d", &n, &x);
  8. for(i=1;i<=n;i++)
  9. {
  10. scanf(" %lld", &c[i]);
  11. if(i==1)
  12. {
  13. idm=1;
  14. me=c[i];
  15. }
  16. else if(c[i]<me || (c[i]==me && ((x-i>=0 && x-idm>=0 && x-i<x-idm) || (x-i<0 && x-idm<0 && i-x>idm-x) )))
  17. {
  18. idm=i;
  19. me=c[i];
  20. }
  21. }
  22. for(i=1;i<=n;i++)
  23. {
  24. if(idm<=x)
  25. {
  26. if(i<idm || i>x)
  27. {
  28. c[i] -= me;
  29. at+=me;
  30. }
  31. else
  32. {
  33. c[i] -= me+1;
  34. at+=me+1;
  35. }
  36. }
  37. else
  38. {
  39. if(i<x || i>idm)
  40. {
  41. c[i] -= me+1;
  42. at+=me+1;
  43. }
  44. else
  45. {
  46. c[i]-= me;
  47. at += me;
  48. }
  49. }
  50. }
  51. c[idm] = at-1;
  52. for(i=1;i<=n;i++)
  53. printf("%lld ", c[i]);
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0s 5276KB
stdin
5 2
3 2 0 2 7
stdout
2 2 2 1 6