#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <numeric>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <ctime>
#include <chrono>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128_t int128;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const char en = '\n';
const int INF = 1e9 + 7;
const ll INFLL = 1e18;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifdef __APPLE__
#include "debug.h"
//#define debug(...) 42
#else
#define debug(...) 42
#endif
void solve() {
int n;
ll m;
cin >> n >> m;
vector<ll> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
a[i] = max(a[i], b[i]);
}
ll l = 0, r = 2e18;
auto check = [&](ll md) -> bool {
ll days = 0;
for (int i = 0; i < n; ++i) {
if (m * a[i] >= md) {
days += (md + a[i] - 1) / a[i];
}
else {
ll musor = md - a[i] * m;
days += m;
days += (musor + b[i] - 1) / b[i];
}
if (days > 1LL * n * m) {
return false;
}
}
return days <= 1LL * n * m;
};
while (r - l > 1) {
ll md = l + (r - l) / 2;
if (check(md)) {
l = md;
} else {
r = md;
}
}
cout << l << en;
}
int main() {
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
116 ms |
10760 KB |
Output is correct |
12 |
Correct |
110 ms |
10764 KB |
Output is correct |
13 |
Correct |
91 ms |
8720 KB |
Output is correct |
14 |
Correct |
74 ms |
8844 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
32 ms |
6084 KB |
Output is correct |
17 |
Correct |
118 ms |
11460 KB |
Output is correct |
18 |
Correct |
102 ms |
10700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
32 ms |
6084 KB |
Output is correct |
3 |
Correct |
118 ms |
11460 KB |
Output is correct |
4 |
Correct |
102 ms |
10700 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
56 ms |
5560 KB |
Output is correct |
14 |
Correct |
40 ms |
3820 KB |
Output is correct |
15 |
Correct |
25 ms |
2888 KB |
Output is correct |
16 |
Correct |
23 ms |
2416 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
116 ms |
10760 KB |
Output is correct |
12 |
Correct |
110 ms |
10764 KB |
Output is correct |
13 |
Correct |
91 ms |
8720 KB |
Output is correct |
14 |
Correct |
74 ms |
8844 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
56 ms |
5560 KB |
Output is correct |
24 |
Correct |
40 ms |
3820 KB |
Output is correct |
25 |
Correct |
25 ms |
2888 KB |
Output is correct |
26 |
Correct |
23 ms |
2416 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
588 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
32 ms |
6084 KB |
Output is correct |
36 |
Correct |
118 ms |
11460 KB |
Output is correct |
37 |
Correct |
102 ms |
10700 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
328 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
3 ms |
468 KB |
Output is correct |
46 |
Correct |
4 ms |
636 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
19 ms |
1992 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
3 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
328 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
52 ms |
5452 KB |
Output is correct |
56 |
Correct |
36 ms |
3276 KB |
Output is correct |
57 |
Correct |
29 ms |
3160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
56 ms |
5560 KB |
Output is correct |
10 |
Correct |
40 ms |
3820 KB |
Output is correct |
11 |
Correct |
25 ms |
2888 KB |
Output is correct |
12 |
Correct |
23 ms |
2416 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
32 ms |
6084 KB |
Output is correct |
22 |
Correct |
118 ms |
11460 KB |
Output is correct |
23 |
Correct |
102 ms |
10700 KB |
Output is correct |
24 |
Correct |
32 ms |
1952 KB |
Output is correct |
25 |
Correct |
76 ms |
4980 KB |
Output is correct |
26 |
Correct |
13 ms |
1364 KB |
Output is correct |
27 |
Correct |
116 ms |
10804 KB |
Output is correct |
28 |
Correct |
126 ms |
10760 KB |
Output is correct |
29 |
Correct |
108 ms |
10808 KB |
Output is correct |
30 |
Correct |
149 ms |
10812 KB |
Output is correct |
31 |
Correct |
213 ms |
10880 KB |
Output is correct |
32 |
Correct |
116 ms |
6184 KB |
Output is correct |
33 |
Correct |
195 ms |
11464 KB |
Output is correct |
34 |
Correct |
103 ms |
6092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
116 ms |
10760 KB |
Output is correct |
12 |
Correct |
110 ms |
10764 KB |
Output is correct |
13 |
Correct |
91 ms |
8720 KB |
Output is correct |
14 |
Correct |
74 ms |
8844 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
56 ms |
5560 KB |
Output is correct |
24 |
Correct |
40 ms |
3820 KB |
Output is correct |
25 |
Correct |
25 ms |
2888 KB |
Output is correct |
26 |
Correct |
23 ms |
2416 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
588 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
328 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
3 ms |
468 KB |
Output is correct |
42 |
Correct |
4 ms |
636 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
19 ms |
1992 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
3 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
328 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
52 ms |
5452 KB |
Output is correct |
52 |
Correct |
36 ms |
3276 KB |
Output is correct |
53 |
Correct |
29 ms |
3160 KB |
Output is correct |
54 |
Correct |
32 ms |
1952 KB |
Output is correct |
55 |
Correct |
76 ms |
4980 KB |
Output is correct |
56 |
Correct |
13 ms |
1364 KB |
Output is correct |
57 |
Correct |
116 ms |
10804 KB |
Output is correct |
58 |
Correct |
126 ms |
10760 KB |
Output is correct |
59 |
Correct |
108 ms |
10808 KB |
Output is correct |
60 |
Correct |
149 ms |
10812 KB |
Output is correct |
61 |
Correct |
213 ms |
10880 KB |
Output is correct |
62 |
Correct |
116 ms |
6184 KB |
Output is correct |
63 |
Correct |
195 ms |
11464 KB |
Output is correct |
64 |
Correct |
103 ms |
6092 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
32 ms |
6084 KB |
Output is correct |
67 |
Correct |
118 ms |
11460 KB |
Output is correct |
68 |
Correct |
102 ms |
10700 KB |
Output is correct |
69 |
Correct |
24 ms |
1364 KB |
Output is correct |
70 |
Correct |
6 ms |
592 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
34 ms |
1748 KB |
Output is correct |
73 |
Correct |
7 ms |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
114 ms |
10808 KB |
Output is correct |
76 |
Correct |
123 ms |
10820 KB |
Output is correct |
77 |
Correct |
131 ms |
10752 KB |
Output is correct |
78 |
Correct |
169 ms |
10880 KB |
Output is correct |
79 |
Correct |
218 ms |
10752 KB |
Output is correct |
80 |
Correct |
264 ms |
10680 KB |
Output is correct |
81 |
Correct |
157 ms |
8772 KB |
Output is correct |
82 |
Correct |
120 ms |
8896 KB |
Output is correct |