Advertisement
Ritam_C

Education_Codeforces

Apr 12th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long int
  4. #define ld long double
  5. #define pb push_back
  6. #define p_b pop_back
  7. #define si stack<int>
  8. #define sll stack<ll>
  9. #define sc stack<char>
  10. #define vi vector<int>
  11. #define vll vector<ll>
  12. #define mii map<int, int>
  13. #define msi map<string, int>
  14. #define mci map<char, int>
  15. #define qc queue<char>
  16. #define qi queue<int>
  17. #define qll queue<ll>
  18. using namespace std;
  19.  
  20. int main(){
  21.     ios_base::sync_with_stdio(false);
  22.     cin.tie(NULL);
  23.     int t;
  24.     cin >> t;
  25.     while(t--){
  26.         int n;
  27.         ll m;
  28.         cin >> n >> m;
  29.         ll a[n], b[n], dp[n] = {0}, tot = 0, count = 0;
  30.         for(int i = 0; i < n; i++){
  31.             cin >> a[i];
  32.         }
  33.         for(int i = 0; i < n-1; i++){
  34.             cin >> b[i];
  35.         }
  36.         b[n-1] = 0;
  37.         for(int i = 0; i < n; i++){
  38.             dp[i] = count;
  39.             dp[i] += ((m-tot)%a[i] == 0) ? (m-tot)/a[i] : (m-tot)/a[i]+1;
  40.             ll cc = ((b[i]-tot)%a[i] == 0) ? (b[i]-tot)/a[i] : (b[i]-tot)/a[i]+1;
  41.             if(tot >= b[i]){
  42.                 tot -= b[i];
  43.                 count++;
  44.             } else{
  45.                 if(tot+a[i] > b[i]){
  46.                     tot += a[i]-b[i];
  47.                     count += 2;
  48.                 } else{
  49.                     tot += cc*a[i]-b[i];
  50.                     count += cc+1;
  51.                 }
  52.             }
  53.         }
  54.         int min = dp[0];
  55.         for(int i = 0; i < n; i++){
  56.             if(dp[i] < min){
  57.                 min = dp[i];
  58.             }
  59.         }
  60.         cout << min << "\n";
  61.     }
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement