Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- int inf_int=2e9;
- ll inf_ll=2e18;
- typedef pair<int,int> pii;
- #define pb push_back
- const double pi=3.1415926535898;
- #define dout if(debug) cout
- #define fi first
- #define se second
- #define sp setprecision
- #define sz size()
- #define x1 gfgs
- #define y1 asd
- #define rank asdsad
- bool debug=0;
- const int maxn=3e5+107;
- ll mod=1e9+7;
- void solve()
- {
- int n,h;
- cin >> n >> h;
- int a[n];
- bool b[n];
- for(int i=0;i<n;i++)
- {
- cin >> a[i];
- }
- for(int i=0;i<n;i++)
- {
- cin >> b[i];
- }
- int ans=0;
- deque<int> q;
- if(b[0]==0)
- {
- b[0]=1;
- ans++;
- }
- ll sum=a[0];
- int cnt=1;
- deque<int> q1;
- q1.push_back(1);
- q.push_back(a[0]);
- for(int i=1;i<n;i++)
- {
- if(sum-q.front()>=h)
- {
- //cout << "vishel "<<" "<<q.front()<< " " << i <<endl;
- sum=sum-q.front();
- cnt=cnt-q1.front();
- q1.pop_front();
- q.pop_front();
- if(cnt==0 && !q.empty())
- {
- // cout << i << endl;
- ans++;
- q1[q1.sz-1]=1;
- cnt++;
- }
- // cout<<"1 " << i <<" "<<sum<<" "<<" "<<cnt<<endl;
- i--;
- continue;
- }
- else
- {
- q.push_back(a[i]);
- q1.push_back(b[i]);
- sum+=a[i];
- if(b[i])
- {
- cnt++;
- }
- // cout<<"2 " << i <<" "<<sum<<" "<<" "<<cnt<<endl;
- }
- }
- while(!q.empty())
- {
- int x=q.front();
- q.pop_front();
- cnt=cnt-q1.front();
- q1.pop_front();
- if(cnt==0 && !q.empty())
- {
- // cout << x <<endl;
- ans++;
- break;
- }
- }
- cout << ans<<"\n";
- }
- #define FILE "skyscraper_5_21"
- int main()
- {
- // freopen("a.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- // freopen(FILE".in","r",stdin);
- // freopen(FILE".out","w",stdout);
- if(!debug)
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- }
- int t=1;
- cin >> t;
- while(t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement