-
Notifications
You must be signed in to change notification settings - Fork 23
/
1512F.cpp
executable file
·53 lines (46 loc) · 994 Bytes
/
1512F.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Problem Code: 1512F
Time: O(n)
Space: O(1)
Author: Mohammed Shoaib, github.com/Mohammed-Shoaib
*/
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
using namespace std;
int education(int n, int c, vector<int>& a, vector<int>& b) {
int64_t min_days, days, coins;
days = coins = 0;
min_days = numeric_limits<int64_t>::max();
for (int i = 0; i < n; i++) {
// buy the computer without promotion
int64_t need, d;
need = c - coins;
d = max((int64_t) 0, (need + a[i] - 1) / a[i]);
min_days = min(d + days, min_days);
// buy the computer with promotion
if (i + 1 < n) {
need = b[i] - coins;
d = max((int64_t) 0, (need + a[i] - 1) / a[i]);
coins += d * a[i] - b[i];
days += 1 + d;
}
}
return min_days;
}
int main() {
int t;
cin >> t;
while (t--) {
int n, c;
cin >> n >> c;
vector<int> a(n), b(n - 1);
for (int& x: a)
cin >> x;
for (int& x: b)
cin >> x;
cout << education(n, c, a, b) << endl;
}
return 0;
}