#include <bits/stdc++.h>
#include <fstream>
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x)
#endif
typedef long long ll;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
constexpr int LIM = 3e5;
ll A[LIM + 10];
ll B[LIM + 10];
bool czy(ll x, int n, ll m) {
ll wol = 0;
for(int i = 1; i <= n; i++) {
if(A[i] * m >= x) {
wol += m - ((x + A[i] - 1) / A[i]);
}
else {
wol -= ((x - A[i] * m) + B[i] - 1) / B[i];
}
if(wol + (ll)n * m < 0) {
return 0;
}
}
return wol >= 0;
}
void solve() {
//ifstream cin("nazwa.in");
//ofstream cout("nazwa.out");
int 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];
A[i] = max(A[i], B[i]);
}
ll l = 0;
ll r = 1e18;
while(l < r) {
ll mid = (l + r + 1) / 2;
if(czy(mid, n, m)) {
l = mid;
}
else {
r = mid - 1;
}
}
cout << l << '\n';
}
int main() {
fastio();
int t;
//cin >> t;
t = 1;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
4 ms |
2392 KB |
Output is correct |
11 |
Correct |
192 ms |
5028 KB |
Output is correct |
12 |
Correct |
198 ms |
4944 KB |
Output is correct |
13 |
Correct |
161 ms |
4948 KB |
Output is correct |
14 |
Correct |
137 ms |
4944 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
64 ms |
4944 KB |
Output is correct |
17 |
Correct |
214 ms |
5284 KB |
Output is correct |
18 |
Correct |
223 ms |
5108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
64 ms |
4944 KB |
Output is correct |
3 |
Correct |
214 ms |
5284 KB |
Output is correct |
4 |
Correct |
223 ms |
5108 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
0 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
0 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 |
116 ms |
4768 KB |
Output is correct |
14 |
Correct |
84 ms |
4536 KB |
Output is correct |
15 |
Correct |
55 ms |
4688 KB |
Output is correct |
16 |
Correct |
40 ms |
4700 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 |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
0 ms |
2392 KB |
Output is correct |
22 |
Correct |
2 ms |
2392 KB |
Output is correct |
23 |
Correct |
4 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 |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
4 ms |
2392 KB |
Output is correct |
11 |
Correct |
192 ms |
5028 KB |
Output is correct |
12 |
Correct |
198 ms |
4944 KB |
Output is correct |
13 |
Correct |
161 ms |
4948 KB |
Output is correct |
14 |
Correct |
137 ms |
4944 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
0 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
0 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 |
116 ms |
4768 KB |
Output is correct |
24 |
Correct |
84 ms |
4536 KB |
Output is correct |
25 |
Correct |
55 ms |
4688 KB |
Output is correct |
26 |
Correct |
40 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
0 ms |
2392 KB |
Output is correct |
32 |
Correct |
2 ms |
2392 KB |
Output is correct |
33 |
Correct |
4 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
64 ms |
4944 KB |
Output is correct |
36 |
Correct |
214 ms |
5284 KB |
Output is correct |
37 |
Correct |
223 ms |
5108 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 |
0 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 |
6 ms |
2396 KB |
Output is correct |
46 |
Correct |
9 ms |
2652 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
36 ms |
5460 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
4 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2744 KB |
Output is correct |
54 |
Correct |
1 ms |
2496 KB |
Output is correct |
55 |
Correct |
103 ms |
7520 KB |
Output is correct |
56 |
Correct |
57 ms |
5824 KB |
Output is correct |
57 |
Correct |
51 ms |
5972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 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 |
116 ms |
4768 KB |
Output is correct |
10 |
Correct |
84 ms |
4536 KB |
Output is correct |
11 |
Correct |
55 ms |
4688 KB |
Output is correct |
12 |
Correct |
40 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
0 ms |
2392 KB |
Output is correct |
18 |
Correct |
2 ms |
2392 KB |
Output is correct |
19 |
Correct |
4 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
64 ms |
4944 KB |
Output is correct |
22 |
Correct |
214 ms |
5284 KB |
Output is correct |
23 |
Correct |
223 ms |
5108 KB |
Output is correct |
24 |
Correct |
45 ms |
5460 KB |
Output is correct |
25 |
Correct |
118 ms |
7068 KB |
Output is correct |
26 |
Correct |
24 ms |
5212 KB |
Output is correct |
27 |
Correct |
199 ms |
10836 KB |
Output is correct |
28 |
Correct |
204 ms |
10772 KB |
Output is correct |
29 |
Correct |
205 ms |
10840 KB |
Output is correct |
30 |
Correct |
236 ms |
10904 KB |
Output is correct |
31 |
Correct |
303 ms |
10836 KB |
Output is correct |
32 |
Correct |
139 ms |
6168 KB |
Output is correct |
33 |
Correct |
338 ms |
11376 KB |
Output is correct |
34 |
Correct |
135 ms |
6288 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 |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
4 ms |
2392 KB |
Output is correct |
11 |
Correct |
192 ms |
5028 KB |
Output is correct |
12 |
Correct |
198 ms |
4944 KB |
Output is correct |
13 |
Correct |
161 ms |
4948 KB |
Output is correct |
14 |
Correct |
137 ms |
4944 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
0 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
0 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 |
116 ms |
4768 KB |
Output is correct |
24 |
Correct |
84 ms |
4536 KB |
Output is correct |
25 |
Correct |
55 ms |
4688 KB |
Output is correct |
26 |
Correct |
40 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
0 ms |
2392 KB |
Output is correct |
32 |
Correct |
2 ms |
2392 KB |
Output is correct |
33 |
Correct |
4 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
0 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 |
6 ms |
2396 KB |
Output is correct |
42 |
Correct |
9 ms |
2652 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
36 ms |
5460 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
4 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2744 KB |
Output is correct |
50 |
Correct |
1 ms |
2496 KB |
Output is correct |
51 |
Correct |
103 ms |
7520 KB |
Output is correct |
52 |
Correct |
57 ms |
5824 KB |
Output is correct |
53 |
Correct |
51 ms |
5972 KB |
Output is correct |
54 |
Correct |
45 ms |
5460 KB |
Output is correct |
55 |
Correct |
118 ms |
7068 KB |
Output is correct |
56 |
Correct |
24 ms |
5212 KB |
Output is correct |
57 |
Correct |
199 ms |
10836 KB |
Output is correct |
58 |
Correct |
204 ms |
10772 KB |
Output is correct |
59 |
Correct |
205 ms |
10840 KB |
Output is correct |
60 |
Correct |
236 ms |
10904 KB |
Output is correct |
61 |
Correct |
303 ms |
10836 KB |
Output is correct |
62 |
Correct |
139 ms |
6168 KB |
Output is correct |
63 |
Correct |
338 ms |
11376 KB |
Output is correct |
64 |
Correct |
135 ms |
6288 KB |
Output is correct |
65 |
Correct |
1 ms |
2392 KB |
Output is correct |
66 |
Correct |
64 ms |
4944 KB |
Output is correct |
67 |
Correct |
214 ms |
5284 KB |
Output is correct |
68 |
Correct |
223 ms |
5108 KB |
Output is correct |
69 |
Correct |
36 ms |
5260 KB |
Output is correct |
70 |
Correct |
8 ms |
2652 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
54 ms |
5460 KB |
Output is correct |
73 |
Correct |
13 ms |
2652 KB |
Output is correct |
74 |
Correct |
1 ms |
2396 KB |
Output is correct |
75 |
Correct |
206 ms |
11116 KB |
Output is correct |
76 |
Correct |
238 ms |
10916 KB |
Output is correct |
77 |
Correct |
223 ms |
11164 KB |
Output is correct |
78 |
Correct |
270 ms |
10924 KB |
Output is correct |
79 |
Correct |
306 ms |
11120 KB |
Output is correct |
80 |
Correct |
329 ms |
10916 KB |
Output is correct |
81 |
Correct |
288 ms |
8936 KB |
Output is correct |
82 |
Correct |
277 ms |
8936 KB |
Output is correct |