fork download
  1. #define _CRT_SECURE_NO_WARNINGS 1
  2. #include <vector>
  3. #include <map>
  4. #include <set>
  5. #include <bitset>
  6. #include <algorithm>
  7. #include <numeric>
  8. #include <sstream>
  9. #include <iostream>
  10. #include <cmath>
  11. #include<cstring>
  12. #include <cstdio>
  13. #include <stack>
  14. #include<iomanip>
  15. #include<queue>
  16. #include<functional>
  17. #include<iterator>
  18. #include<new>
  19. #include<cstdlib>
  20. using namespace std;
  21. #define INF 2000000000
  22. #define scll(x) scanf("%lld",&x);
  23. #define sci(x) scanf("%d",&x);
  24. #define scc(x) scanf("%c", &c);
  25. #define MOD 1000000007
  26. #define EPS 1e-6
  27. typedef long long ll;
  28. typedef pair<int, int> pi;
  29. typedef pair<double, double> pdl;
  30. typedef pair<long long, long long> pll;
  31.  
  32. ll gcd(ll a, ll b) {
  33. return b == 0 ? a : gcd(b, a%b);
  34. }
  35.  
  36. ll lcm(ll a, ll b) {
  37. return a*b / gcd(a, b);
  38. }
  39.  
  40. ll n, r, k;
  41. ll a[20020], x[20020];
  42.  
  43.  
  44. int main()
  45. {
  46. #ifndef ONLINE_JUDGE
  47. freopen("input.txt", "r", stdin);
  48. //freopen("output.txt", "w", stdout);
  49. #endif
  50. int cNo = 1;
  51. while (cin >> n >> r >> k && n > 0) {
  52. ll startIdx = (r - 1)*n + (k - 1);
  53. ll endIdx = 0;
  54. n *= 2;
  55. for (int i = 0; i < n; i++)
  56. cin >> a[i];
  57. reverse(a + n / 2, a + n);
  58. if (startIdx >= n/2)
  59. startIdx = n - startIdx + n / 2 - 1;
  60.  
  61. for (int i = 0; i < n; i++) {
  62. if (i < startIdx)
  63. x[i] = (n - startIdx) + a[i]*n + 1LL * (i + 1);
  64. else
  65. x[i] = (i*1LL - startIdx) + a[i]*n;
  66. }
  67. for (int i = 0; i < n; i++) {
  68. if (x[i] < x[endIdx])
  69. endIdx = i;
  70. }
  71. ll actualEnd = (endIdx % n - x[endIdx] % n + 3*n) % n;
  72.  
  73. printf("Case %d:\n", cNo);
  74. if (actualEnd != startIdx) {
  75. printf("INVALID\n");
  76. cNo++;
  77. continue;
  78. }
  79.  
  80. ll distNum = x[endIdx];
  81. for (int i = startIdx; i < n; i++) {
  82. a[i]--;
  83. distNum--;
  84. }
  85. for (int i = 0; i < n; i++) {
  86. a[i] -= distNum / n;
  87. }
  88. distNum %= n;
  89. for (int i = 0; i < distNum; i++)
  90. a[i]--;
  91. a[endIdx] = x[endIdx];
  92. reverse(a + n/2, a + n);
  93.  
  94. for (int i = 0; i < n; i++) {
  95. if (i == n / 2)
  96. cout << endl;
  97. cout << a[i] << ' ';
  98. }
  99. cout << endl;
  100. cNo++;
  101. }
  102.  
  103.  
  104.  
  105. return 0;
  106. }
  107.  
Success #stdin #stdout 0s 15552KB
stdin
Standard input is empty
stdout
Standard output is empty