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. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25. vector<int> h;
  26.  
  27. int consistency(int n, int k){
  28.  
  29. if(n==1){
  30. if(a[0] > k) return 0;
  31. return 1;
  32. }
  33.  
  34. int sum = 0;
  35. int ans = 0;
  36.  
  37. int s = 0, e = 0;
  38. while(e<n){
  39. sum += a[e];
  40.  
  41. while(s<=e && sum > k){
  42. sum -= a[s];
  43. s++;
  44. }
  45.  
  46. if(e==0 || h[e-1] % h[e] == 0){
  47. ans = max(ans, e-s+1);
  48. e++;
  49. }
  50. else{
  51. //* if x % y != 0
  52. //* [ a b c x y] => a b c x [ y ]
  53.  
  54. s = e;
  55. sum = a[e];
  56. if(sum <= k) ans = max(ans, e-s+1);
  57.  
  58. e++;
  59. }
  60. }
  61.  
  62. return ans;
  63. }
  64.  
  65. void solve() {
  66.  
  67. int n, k;
  68. cin>>n >> k;
  69.  
  70. a.resize(n);
  71. h.resize(n);
  72. for(int i=0; i<n; i++) cin >> a[i];
  73. for(int i=0; i<n; i++) cin >> h[i];
  74.  
  75. cout << consistency(n, k) << endl;
  76.  
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. int32_t main() {
  85. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  86.  
  87. int t = 1;
  88. cin >> t;
  89. while (t--) {
  90. solve();
  91. }
  92.  
  93. return 0;
  94. }
Success #stdin #stdout 0s 5320KB
stdin
5
5 12
3 2 4 1 8
4 4 2 4 1
4 8
5 4 1 2
6 2 3 1
3 12
7 9 10
2 2 4
1 10
11
1
7 10
2 6 3 1 5 10 6
72 24 24 12 4 4 2
stdout
3
2
1
0
3