#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ldb,ldb> pdd;
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for(auto& a : x)
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
const int mod = 1000000007;
const ll inf = 1e18 + 5;
const int mxN = 300005;
int n; ll m;
ll A[mxN];
ll B[mxN];
bool check(ll X){
ll uk = 0;
ff(i,1,n){
if(A[i] > B[i]){
ll a = min(m, (X + A[i] - 1) / A[i]);
ll Y = max(0ll, X - a * A[i]);
ll b = (Y + B[i] - 1) / B[i];
uk += a; uk += b;
}
else{
ll b = (X + B[i] - 1) / B[i];
uk += b;
}
if(uk > 1ll * n * m)return 0;
}
return 1;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
ff(i,1,n)cin >> A[i];
ff(i,1,n)cin >> B[i];
ll l = 0, r = inf, ans = 0;
while(l <= r){
ll mid = l + (r - l) / 2;
if(check(mid)){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << ans << '\n';
return 0;
}
/*
3 3
19 4 5
2 6 2
2 1
9 7
2 6
5 60000
630510219 369411957 874325200 990002527 567203997
438920902 634940661 593780254 315929832 420627496
4 25
1 2 3 4
1 2 3 4
// probati bojenje sahovski
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 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 |
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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
80 ms |
5132 KB |
Output is correct |
12 |
Correct |
82 ms |
5088 KB |
Output is correct |
13 |
Correct |
48 ms |
4996 KB |
Output is correct |
14 |
Correct |
53 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
23 ms |
6140 KB |
Output is correct |
17 |
Correct |
60 ms |
11348 KB |
Output is correct |
18 |
Correct |
62 ms |
10724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
23 ms |
6140 KB |
Output is correct |
3 |
Correct |
60 ms |
11348 KB |
Output is correct |
4 |
Correct |
62 ms |
10724 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
30 ms |
2652 KB |
Output is correct |
14 |
Correct |
19 ms |
3160 KB |
Output is correct |
15 |
Correct |
15 ms |
1624 KB |
Output is correct |
16 |
Correct |
13 ms |
2908 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 |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
604 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 |
348 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
80 ms |
5132 KB |
Output is correct |
12 |
Correct |
82 ms |
5088 KB |
Output is correct |
13 |
Correct |
48 ms |
4996 KB |
Output is correct |
14 |
Correct |
53 ms |
4948 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 |
348 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 |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
30 ms |
2652 KB |
Output is correct |
24 |
Correct |
19 ms |
3160 KB |
Output is correct |
25 |
Correct |
15 ms |
1624 KB |
Output is correct |
26 |
Correct |
13 ms |
2908 KB |
Output is correct |
27 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
23 ms |
6140 KB |
Output is correct |
36 |
Correct |
60 ms |
11348 KB |
Output is correct |
37 |
Correct |
62 ms |
10724 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
464 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
2 ms |
656 KB |
Output is correct |
46 |
Correct |
3 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
15 ms |
2152 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
40 ms |
5468 KB |
Output is correct |
56 |
Correct |
17 ms |
3312 KB |
Output is correct |
57 |
Correct |
18 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
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 |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
30 ms |
2652 KB |
Output is correct |
10 |
Correct |
19 ms |
3160 KB |
Output is correct |
11 |
Correct |
15 ms |
1624 KB |
Output is correct |
12 |
Correct |
13 ms |
2908 KB |
Output is correct |
13 |
Correct |
0 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 |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
23 ms |
6140 KB |
Output is correct |
22 |
Correct |
60 ms |
11348 KB |
Output is correct |
23 |
Correct |
62 ms |
10724 KB |
Output is correct |
24 |
Correct |
12 ms |
1884 KB |
Output is correct |
25 |
Correct |
35 ms |
4948 KB |
Output is correct |
26 |
Correct |
7 ms |
3164 KB |
Output is correct |
27 |
Correct |
58 ms |
10864 KB |
Output is correct |
28 |
Correct |
60 ms |
10836 KB |
Output is correct |
29 |
Correct |
60 ms |
10836 KB |
Output is correct |
30 |
Correct |
64 ms |
10832 KB |
Output is correct |
31 |
Correct |
77 ms |
10948 KB |
Output is correct |
32 |
Correct |
49 ms |
6224 KB |
Output is correct |
33 |
Correct |
84 ms |
11600 KB |
Output is correct |
34 |
Correct |
41 ms |
6236 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 |
348 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
80 ms |
5132 KB |
Output is correct |
12 |
Correct |
82 ms |
5088 KB |
Output is correct |
13 |
Correct |
48 ms |
4996 KB |
Output is correct |
14 |
Correct |
53 ms |
4948 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 |
348 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 |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
30 ms |
2652 KB |
Output is correct |
24 |
Correct |
19 ms |
3160 KB |
Output is correct |
25 |
Correct |
15 ms |
1624 KB |
Output is correct |
26 |
Correct |
13 ms |
2908 KB |
Output is correct |
27 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
464 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
656 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
15 ms |
2152 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
40 ms |
5468 KB |
Output is correct |
52 |
Correct |
17 ms |
3312 KB |
Output is correct |
53 |
Correct |
18 ms |
3160 KB |
Output is correct |
54 |
Correct |
12 ms |
1884 KB |
Output is correct |
55 |
Correct |
35 ms |
4948 KB |
Output is correct |
56 |
Correct |
7 ms |
3164 KB |
Output is correct |
57 |
Correct |
58 ms |
10864 KB |
Output is correct |
58 |
Correct |
60 ms |
10836 KB |
Output is correct |
59 |
Correct |
60 ms |
10836 KB |
Output is correct |
60 |
Correct |
64 ms |
10832 KB |
Output is correct |
61 |
Correct |
77 ms |
10948 KB |
Output is correct |
62 |
Correct |
49 ms |
6224 KB |
Output is correct |
63 |
Correct |
84 ms |
11600 KB |
Output is correct |
64 |
Correct |
41 ms |
6236 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
23 ms |
6140 KB |
Output is correct |
67 |
Correct |
60 ms |
11348 KB |
Output is correct |
68 |
Correct |
62 ms |
10724 KB |
Output is correct |
69 |
Correct |
13 ms |
3160 KB |
Output is correct |
70 |
Correct |
3 ms |
604 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
17 ms |
1880 KB |
Output is correct |
73 |
Correct |
4 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
86 ms |
11020 KB |
Output is correct |
76 |
Correct |
90 ms |
10836 KB |
Output is correct |
77 |
Correct |
94 ms |
10836 KB |
Output is correct |
78 |
Correct |
117 ms |
10840 KB |
Output is correct |
79 |
Correct |
120 ms |
10944 KB |
Output is correct |
80 |
Correct |
128 ms |
10940 KB |
Output is correct |
81 |
Correct |
73 ms |
8784 KB |
Output is correct |
82 |
Correct |
117 ms |
8956 KB |
Output is correct |