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. //* prefix sum
  33.  
  34. int consistency1(int n, int x, int y){
  35.  
  36. int ans = INF;
  37.  
  38. for(int k=0; k<y; k++){
  39.  
  40. vector<int> prefix(n/y+2);
  41.  
  42. for(int i=k, j=1; i<n; i+=y, j++){
  43. prefix[j] = prefix[j-1] + a[i];
  44.  
  45. if(j-x < 0) continue;
  46.  
  47. int sum = prefix[j] - prefix[j-x];
  48.  
  49. ans = min(ans, sum);
  50. }
  51. }
  52.  
  53. return ans;
  54. }
  55.  
  56.  
  57.  
  58. //* SLiding window
  59.  
  60. int consistency2(int n, int x, int y){
  61.  
  62. int ans = INF;
  63.  
  64. for(int k=0; k<y; k++){
  65.  
  66. int sum = 0;
  67. for(int i=k; i<n; i+=y){
  68. sum += a[i];
  69.  
  70. if(i >= y*x){
  71. sum -= a[i-y*x];
  72. }
  73.  
  74. if(i >= y*(x-1)){
  75. ans = min(ans, sum);
  76. }
  77. }
  78. }
  79.  
  80. return ans;
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. int practice(int n, int x, int y){
  98.  
  99.  
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. void solve() {
  112.  
  113. int n, x, y;
  114. cin>> n >> x >> y;
  115.  
  116. a.resize(n);
  117. for(int i=0; i<n; i++) cin >> a[i];
  118.  
  119. cout << consistency1(n, x, y) << " " << consistency2(n, x, y) << endl;
  120.  
  121. // cout << practice(n, x, y) << endl;
  122.  
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130. int32_t main() {
  131. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  132.  
  133. int t = 1;
  134. cin >> t;
  135. while (t--) {
  136. solve();
  137. }
  138.  
  139. return 0;
  140. }
  141.  
Success #stdin #stdout 0.01s 5324KB
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