#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ln '\n'
const int N = 3e5 + 5;
const ll INF = 3e15 + 5;
ll n, m, a[N], b[N];
inline ll ceil(ll x, ll y) {return (x + y - 1) / y;}
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 = 25, r = 25, ans = 0;
ll l = 0, r = INF, ans = 0;
while (l <= r){
ll tar = (l + r) / 2;
ll free, need; free = need = 0;
for (int i = 0; i < n; i++){
if (b[i] >= a[i]) {
free += max(0LL, m - ceil(tar, b[i]));
need += max(0LL, ceil(tar, b[i]) - m);
} else {
ll go_lesson = min(m, ceil(tar, a[i]));
need += max(0LL, ceil(tar - a[i] * go_lesson, b[i]));
free += max(0LL, m - go_lesson);
}
// cout << need << ' ' << free << ln;
}
if (need <= free) {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();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
111 ms |
10728 KB |
Output is correct |
12 |
Correct |
107 ms |
10928 KB |
Output is correct |
13 |
Correct |
74 ms |
8928 KB |
Output is correct |
14 |
Incorrect |
126 ms |
8952 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
2396 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 |
344 KB |
Output is correct |
9 |
Correct |
46 ms |
5528 KB |
Output is correct |
10 |
Correct |
21 ms |
3764 KB |
Output is correct |
11 |
Correct |
16 ms |
2932 KB |
Output is correct |
12 |
Correct |
14 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
55 ms |
6120 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
111 ms |
10728 KB |
Output is correct |
12 |
Correct |
107 ms |
10928 KB |
Output is correct |
13 |
Correct |
74 ms |
8928 KB |
Output is correct |
14 |
Incorrect |
126 ms |
8952 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
2396 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 |
344 KB |
Output is correct |
9 |
Correct |
46 ms |
5528 KB |
Output is correct |
10 |
Correct |
21 ms |
3764 KB |
Output is correct |
11 |
Correct |
16 ms |
2932 KB |
Output is correct |
12 |
Correct |
14 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
55 ms |
6120 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
111 ms |
10728 KB |
Output is correct |
12 |
Correct |
107 ms |
10928 KB |
Output is correct |
13 |
Correct |
74 ms |
8928 KB |
Output is correct |
14 |
Incorrect |
126 ms |
8952 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |