fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cassert>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int MAX = 10000;
  9.  
  10. int getK(vector<int> a) {
  11. int n = a.size();
  12. int sum = 0;
  13. for (int i = 0; i < n; i++) {
  14. sum += a[i];
  15. }
  16. for (int i = n; i < n * n; i++) {
  17. a.push_back(sum / n);
  18. sum -= a[i - n];
  19. sum += a[i];
  20. }
  21. /*
  22. for (int i = 0; i < n * n; i++) {
  23. fprintf(stderr, "%d ", a[i]);
  24. }
  25. fprintf(stderr, "\n");
  26. */
  27. int equal = 0;
  28. int len = n;
  29. for (int i = n; i < n * n; i++) {
  30. if (a[i] == a[i - n]) {
  31. equal++;
  32. if (equal >= n) {
  33. len = i;
  34. break;
  35. }
  36. } else {
  37. equal = 0;
  38. }
  39. }
  40. return len;
  41. }
  42.  
  43.  
  44. // void test() {
  45. // for (int n = 11; n <= 15; n++) {
  46. // vector<int> a(n);
  47. // for (int i = 0; i < n; i++) {
  48. // a[i] = i + 1;
  49. // }
  50. // int maxK = 0;
  51. // do {
  52. // int K = getK(a);
  53. // maxK = max(maxK, K);
  54. // } while (next_permutation(a.begin(), a.end()));
  55. // fprintf(stderr, "n = %d, maxK = %d\n", n, maxK);
  56. // }
  57. // }
  58.  
  59. int main() {
  60. int T = 100;
  61. scanf("%d", &T);
  62. assert(T >= 1 && T <= 10);
  63. while (T--) {
  64. int n;
  65. scanf("%d", &n);
  66. assert(n >= 1 && n <= 1000);
  67. vector<int> a(n);
  68. int sum = 0;
  69. for (int i = 0; i < n; i++) {
  70. scanf("%d", &a[i]);
  71. assert(a[i] >= 1 && a[i] <= 1000);
  72. sum += a[i];
  73. }
  74. for (int i = n; i < 2000000; i++) {
  75. a.push_back(sum / n);
  76. sum -= a[i - n];
  77. assert(sum >= 0);
  78. sum += a[i];
  79. }
  80. int Q;
  81. scanf("%d", &Q);
  82. assert(Q >= 1 && Q <= 100000);
  83. while (Q--) {
  84. int K;
  85. scanf("%d", &K);
  86. assert(K >= 1 && K <= (int) 1e9);
  87. K--;
  88. int ans = K < a.size() ? a[K] : a.back();
  89. printf("%d\n", ans);
  90. }
  91. }
  92. return 0;
  93. }
  94.  
Runtime error #stdin #stdout #stderr 0s 4396KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog: prog.cpp:62: int main(): Assertion `T >= 1 && T <= 10' failed.