Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long int
- #define ld long double
- #define pb push_back
- #define p_b pop_back
- #define si stack<int>
- #define sll stack<ll>
- #define sc stack<char>
- #define vi vector<int>
- #define vll vector<ll>
- #define mii map<int, int>
- #define msi map<string, int>
- #define mci map<char, int>
- #define qc queue<char>
- #define qi queue<int>
- #define qll queue<ll>
- using namespace std;
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int t;
- cin >> t;
- while(t--){
- int n;
- ll m;
- cin >> n >> m;
- ll a[n], b[n], dp[n] = {0}, tot = 0, count = 0;
- for(int i = 0; i < n; i++){
- cin >> a[i];
- }
- for(int i = 0; i < n-1; i++){
- cin >> b[i];
- }
- b[n-1] = 0;
- for(int i = 0; i < n; i++){
- dp[i] = count;
- dp[i] += ((m-tot)%a[i] == 0) ? (m-tot)/a[i] : (m-tot)/a[i]+1;
- ll cc = ((b[i]-tot)%a[i] == 0) ? (b[i]-tot)/a[i] : (b[i]-tot)/a[i]+1;
- if(tot >= b[i]){
- tot -= b[i];
- count++;
- } else{
- if(tot+a[i] > b[i]){
- tot += a[i]-b[i];
- count += 2;
- } else{
- tot += cc*a[i]-b[i];
- count += cc+1;
- }
- }
- }
- int min = dp[0];
- for(int i = 0; i < n; i++){
- if(dp[i] < min){
- min = dp[i];
- }
- }
- cout << min << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement