Advertisement
Guest User

Untitled

a guest
May 8th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5. typedef unsigned long long ull;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. int inf_int=2e9;
  9. ll inf_ll=2e18;
  10. typedef pair<int,int> pii;
  11. #define pb push_back
  12. const double pi=3.1415926535898;
  13. #define dout if(debug) cout
  14. #define fi first
  15. #define se second
  16. #define sp setprecision
  17. #define sz size()
  18.  
  19.  
  20.  
  21. #define x1 gfgs
  22. #define y1 asd
  23. #define rank asdsad
  24. bool debug=0;
  25. const int maxn=3e5+107;
  26. ll mod=1e9+7;
  27.  
  28. void solve()
  29. {
  30. int n,h;
  31. cin >> n >> h;
  32. int a[n];
  33. bool b[n];
  34. for(int i=0;i<n;i++)
  35. {
  36. cin >> a[i];
  37. }
  38. for(int i=0;i<n;i++)
  39. {
  40. cin >> b[i];
  41. }
  42. int ans=0;
  43. deque<int> q;
  44. if(b[0]==0)
  45. {
  46. b[0]=1;
  47. ans++;
  48. }
  49. ll sum=a[0];
  50. int cnt=1;
  51. deque<int> q1;
  52. q1.push_back(1);
  53. q.push_back(a[0]);
  54. for(int i=1;i<n;i++)
  55. {
  56.  
  57. if(sum-q.front()>=h)
  58. {
  59. //cout << "vishel "<<" "<<q.front()<< " " << i <<endl;
  60. sum=sum-q.front();
  61. cnt=cnt-q1.front();
  62. q1.pop_front();
  63. q.pop_front();
  64. if(cnt==0 && !q.empty())
  65. {
  66. // cout << i << endl;
  67. ans++;
  68. q1[q1.sz-1]=1;
  69. cnt++;
  70. }
  71. // cout<<"1 " << i <<" "<<sum<<" "<<" "<<cnt<<endl;
  72. i--;
  73. continue;
  74. }
  75. else
  76. {
  77. q.push_back(a[i]);
  78. q1.push_back(b[i]);
  79. sum+=a[i];
  80. if(b[i])
  81. {
  82. cnt++;
  83. }
  84. // cout<<"2 " << i <<" "<<sum<<" "<<" "<<cnt<<endl;
  85. }
  86. }
  87. while(!q.empty())
  88. {
  89. int x=q.front();
  90. q.pop_front();
  91. cnt=cnt-q1.front();
  92. q1.pop_front();
  93. if(cnt==0 && !q.empty())
  94. {
  95. // cout << x <<endl;
  96. ans++;
  97. break;
  98. }
  99. }
  100. cout << ans<<"\n";
  101.  
  102.  
  103. }
  104.  
  105.  
  106. #define FILE "skyscraper_5_21"
  107. int main()
  108. {
  109.  
  110. // freopen("a.txt","r",stdin);
  111. // freopen("output.txt","w",stdout);
  112.  
  113. // freopen(FILE".in","r",stdin);
  114. // freopen(FILE".out","w",stdout);
  115. if(!debug)
  116. {
  117. ios_base::sync_with_stdio(0);
  118. cin.tie(0);
  119. cout.tie(0);
  120. }
  121. int t=1;
  122. cin >> t;
  123. while(t--)
  124. solve();
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement