#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ln '\n'
const int N = 3e5 + 5;
const ll INF = 1e18 + 5;
ll n, m, a[N], b[N];
inline ll ceil(ll x, ll y) {
return (x + y - 1) / y;
}
ll cnt(ll go_lesson, ll i, ll tar){
return (m - go_lesson) - max(0LL, ceil(tar - a[i] * go_lesson, b[i]));
}
void solve(){
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
// ll l = 7, r = 7, ans = 0;
ll l = 1, r = INF, ans = 1;
while (l <= r){
ll tar = (l + r) / 2;
uint64_t free, need; free = need = 0;
for (int i = 0; i < n; i++){
ll go_lesson = (cnt(1, i, tar) > cnt(0, i, tar)? 1: 0);
free += m - go_lesson;
need += max(0LL, ceil(tar - a[i] * go_lesson, b[i]));
}
// cout << free << ' ' << need << ln;
if (free >= need) {ans = tar; l = tar + 1;}
else r = tar - 1;
}
cout << ans << ln;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int TT; cin >> TT;
// while (TT--) {solve();}
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
136 ms |
10924 KB |
Output is correct |
12 |
Correct |
153 ms |
10916 KB |
Output is correct |
13 |
Correct |
130 ms |
8840 KB |
Output is correct |
14 |
Correct |
140 ms |
8784 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
128 ms |
6304 KB |
Output is correct |
17 |
Correct |
144 ms |
11088 KB |
Output is correct |
18 |
Correct |
151 ms |
10808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
128 ms |
6304 KB |
Output is correct |
3 |
Correct |
144 ms |
11088 KB |
Output is correct |
4 |
Correct |
151 ms |
10808 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
416 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
78 ms |
5480 KB |
Output is correct |
14 |
Correct |
48 ms |
3932 KB |
Output is correct |
15 |
Correct |
35 ms |
2908 KB |
Output is correct |
16 |
Correct |
27 ms |
2400 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
136 ms |
10924 KB |
Output is correct |
12 |
Correct |
153 ms |
10916 KB |
Output is correct |
13 |
Correct |
130 ms |
8840 KB |
Output is correct |
14 |
Correct |
140 ms |
8784 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
416 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
78 ms |
5480 KB |
Output is correct |
24 |
Correct |
48 ms |
3932 KB |
Output is correct |
25 |
Correct |
35 ms |
2908 KB |
Output is correct |
26 |
Correct |
27 ms |
2400 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
352 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
608 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
128 ms |
6304 KB |
Output is correct |
36 |
Correct |
144 ms |
11088 KB |
Output is correct |
37 |
Correct |
151 ms |
10808 KB |
Output is correct |
38 |
Incorrect |
1 ms |
2400 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
78 ms |
5480 KB |
Output is correct |
10 |
Correct |
48 ms |
3932 KB |
Output is correct |
11 |
Correct |
35 ms |
2908 KB |
Output is correct |
12 |
Correct |
27 ms |
2400 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
352 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
608 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
128 ms |
6304 KB |
Output is correct |
22 |
Correct |
144 ms |
11088 KB |
Output is correct |
23 |
Correct |
151 ms |
10808 KB |
Output is correct |
24 |
Correct |
22 ms |
1880 KB |
Output is correct |
25 |
Correct |
61 ms |
4968 KB |
Output is correct |
26 |
Correct |
15 ms |
3164 KB |
Output is correct |
27 |
Correct |
138 ms |
11000 KB |
Output is correct |
28 |
Correct |
138 ms |
10816 KB |
Output is correct |
29 |
Correct |
139 ms |
11016 KB |
Output is correct |
30 |
Correct |
153 ms |
10836 KB |
Output is correct |
31 |
Correct |
154 ms |
11048 KB |
Output is correct |
32 |
Correct |
131 ms |
6232 KB |
Output is correct |
33 |
Correct |
145 ms |
11600 KB |
Output is correct |
34 |
Correct |
132 ms |
6304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
136 ms |
10924 KB |
Output is correct |
12 |
Correct |
153 ms |
10916 KB |
Output is correct |
13 |
Correct |
130 ms |
8840 KB |
Output is correct |
14 |
Correct |
140 ms |
8784 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
416 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
78 ms |
5480 KB |
Output is correct |
24 |
Correct |
48 ms |
3932 KB |
Output is correct |
25 |
Correct |
35 ms |
2908 KB |
Output is correct |
26 |
Correct |
27 ms |
2400 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
352 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
608 KB |
Output is correct |
34 |
Incorrect |
1 ms |
2400 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |