#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 3e5 + 10;
ll a[N], b[N];
void solve() {
ll n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
ll l = 0, r = 1e18, ans;
while (l <= r) {
ll mid = (l + r) / 2;
ll tot = 0;
for (int i = 1; i <= n; i++) {
if (b[i] >= a[i]) {
tot = (tot + mid / b[i] + bool(mid % b[i]));
} else {
if (a[i] * m >= mid) {
tot += (mid / a[i] + bool(mid % a[i]));
} else {
tot += m;
ll re = mid - a[i] * m;
tot += (re / b[i] + bool(re % b[i]));
}
}
if (tot > n * m)
break;
}
if (tot <= n * m) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
92 ms |
5132 KB |
Output is correct |
12 |
Correct |
91 ms |
4956 KB |
Output is correct |
13 |
Correct |
67 ms |
4956 KB |
Output is correct |
14 |
Correct |
57 ms |
5072 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
26 ms |
5156 KB |
Output is correct |
17 |
Correct |
81 ms |
5376 KB |
Output is correct |
18 |
Correct |
83 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
26 ms |
5156 KB |
Output is correct |
3 |
Correct |
81 ms |
5376 KB |
Output is correct |
4 |
Correct |
83 ms |
4944 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
42 ms |
7552 KB |
Output is correct |
14 |
Correct |
28 ms |
6588 KB |
Output is correct |
15 |
Correct |
20 ms |
5976 KB |
Output is correct |
16 |
Correct |
18 ms |
5724 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
92 ms |
5132 KB |
Output is correct |
12 |
Correct |
91 ms |
4956 KB |
Output is correct |
13 |
Correct |
67 ms |
4956 KB |
Output is correct |
14 |
Correct |
57 ms |
5072 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
42 ms |
7552 KB |
Output is correct |
24 |
Correct |
28 ms |
6588 KB |
Output is correct |
25 |
Correct |
20 ms |
5976 KB |
Output is correct |
26 |
Correct |
18 ms |
5724 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
26 ms |
5156 KB |
Output is correct |
36 |
Correct |
81 ms |
5376 KB |
Output is correct |
37 |
Correct |
83 ms |
4944 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
2 ms |
2652 KB |
Output is correct |
46 |
Correct |
3 ms |
2648 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
16 ms |
5720 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
2 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
45 ms |
7424 KB |
Output is correct |
56 |
Correct |
25 ms |
5980 KB |
Output is correct |
57 |
Correct |
20 ms |
5980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
42 ms |
7552 KB |
Output is correct |
10 |
Correct |
28 ms |
6588 KB |
Output is correct |
11 |
Correct |
20 ms |
5976 KB |
Output is correct |
12 |
Correct |
18 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
2 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
26 ms |
5156 KB |
Output is correct |
22 |
Correct |
81 ms |
5376 KB |
Output is correct |
23 |
Correct |
83 ms |
4944 KB |
Output is correct |
24 |
Correct |
26 ms |
5468 KB |
Output is correct |
25 |
Correct |
63 ms |
7252 KB |
Output is correct |
26 |
Correct |
11 ms |
5208 KB |
Output is correct |
27 |
Correct |
80 ms |
10928 KB |
Output is correct |
28 |
Correct |
84 ms |
10836 KB |
Output is correct |
29 |
Correct |
87 ms |
10836 KB |
Output is correct |
30 |
Correct |
106 ms |
10836 KB |
Output is correct |
31 |
Correct |
180 ms |
11180 KB |
Output is correct |
32 |
Correct |
105 ms |
6224 KB |
Output is correct |
33 |
Correct |
209 ms |
11580 KB |
Output is correct |
34 |
Correct |
104 ms |
6300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
92 ms |
5132 KB |
Output is correct |
12 |
Correct |
91 ms |
4956 KB |
Output is correct |
13 |
Correct |
67 ms |
4956 KB |
Output is correct |
14 |
Correct |
57 ms |
5072 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
42 ms |
7552 KB |
Output is correct |
24 |
Correct |
28 ms |
6588 KB |
Output is correct |
25 |
Correct |
20 ms |
5976 KB |
Output is correct |
26 |
Correct |
18 ms |
5724 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2652 KB |
Output is correct |
42 |
Correct |
3 ms |
2648 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
16 ms |
5720 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
2 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
45 ms |
7424 KB |
Output is correct |
52 |
Correct |
25 ms |
5980 KB |
Output is correct |
53 |
Correct |
20 ms |
5980 KB |
Output is correct |
54 |
Correct |
26 ms |
5468 KB |
Output is correct |
55 |
Correct |
63 ms |
7252 KB |
Output is correct |
56 |
Correct |
11 ms |
5208 KB |
Output is correct |
57 |
Correct |
80 ms |
10928 KB |
Output is correct |
58 |
Correct |
84 ms |
10836 KB |
Output is correct |
59 |
Correct |
87 ms |
10836 KB |
Output is correct |
60 |
Correct |
106 ms |
10836 KB |
Output is correct |
61 |
Correct |
180 ms |
11180 KB |
Output is correct |
62 |
Correct |
105 ms |
6224 KB |
Output is correct |
63 |
Correct |
209 ms |
11580 KB |
Output is correct |
64 |
Correct |
104 ms |
6300 KB |
Output is correct |
65 |
Correct |
1 ms |
2396 KB |
Output is correct |
66 |
Correct |
26 ms |
5156 KB |
Output is correct |
67 |
Correct |
81 ms |
5376 KB |
Output is correct |
68 |
Correct |
83 ms |
4944 KB |
Output is correct |
69 |
Correct |
19 ms |
5352 KB |
Output is correct |
70 |
Correct |
5 ms |
2648 KB |
Output is correct |
71 |
Correct |
1 ms |
2648 KB |
Output is correct |
72 |
Correct |
28 ms |
5464 KB |
Output is correct |
73 |
Correct |
6 ms |
2652 KB |
Output is correct |
74 |
Correct |
1 ms |
2396 KB |
Output is correct |
75 |
Correct |
94 ms |
10836 KB |
Output is correct |
76 |
Correct |
100 ms |
10832 KB |
Output is correct |
77 |
Correct |
108 ms |
10944 KB |
Output is correct |
78 |
Correct |
136 ms |
10944 KB |
Output is correct |
79 |
Correct |
186 ms |
10892 KB |
Output is correct |
80 |
Correct |
197 ms |
10940 KB |
Output is correct |
81 |
Correct |
196 ms |
8960 KB |
Output is correct |
82 |
Correct |
195 ms |
8768 KB |
Output is correct |