fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31.  
  32. int consistency1(int n, int x, int y){
  33.  
  34. int cost = INF;
  35. vector<int> prefix(n+1);
  36.  
  37. for(int i=0; i<n; i++){
  38. if(i-y>=0) prefix[i] = prefix[i-y] + a[i];
  39. else prefix[i] = a[i];
  40. }
  41.  
  42. for(int i = 0; i < n; i++) {
  43.  
  44. if(i - x*y + y < 0) continue;
  45.  
  46. int sum = prefix[i];
  47.  
  48. if(i-x*y >= 0)
  49. sum -= prefix[i-x*y];
  50.  
  51. cost = min(cost, sum);
  52. }
  53.  
  54. return cost;
  55. }
  56.  
  57.  
  58. int consistency2(int n, int x, int y){
  59.  
  60. int cost = INF;
  61.  
  62. for(int i=0; i<y; i++){
  63.  
  64. int s = i, e = i;
  65. int sum = 0;
  66.  
  67. while(e<n){
  68. sum += a[e];
  69. if((e-s)/y + 1 < x){
  70. e+=y;
  71. }
  72. else{
  73. cost = min(cost, sum);
  74. sum -= a[s];
  75. s+=y;
  76. e+=y;
  77. }
  78. }
  79.  
  80. }
  81.  
  82. return cost;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. int practice(int n, int x, int y){
  100.  
  101.  
  102. return 0;
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. void solve() {
  110.  
  111. int n, x, y;
  112. cin>> n >> x >> y;
  113.  
  114. a.resize(n);
  115. for(int i=0; i<n; i++) cin >> a[i];
  116.  
  117. cout << consistency1(n, x, y) << " " << consistency2(n, x, y) << endl;
  118.  
  119.  
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126. int32_t main() {
  127. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  128.  
  129. int t = 1;
  130. cin >> t;
  131. while (t--) {
  132. solve();
  133. }
  134.  
  135. return 0;
  136. }
Success #stdin #stdout 0s 5328KB
stdin
3
4 2 2
4 2 3 7
4 2 3
10 3 4 7
10 3 2
4 2 5 4 3 5 1 4 2 7
stdout
7 7
17 17
6 6