#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long MAXN = 3e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, m;
long long a[MAXN], b[MAXN];
void read()
{
cin >> n >> m;
for (long long i = 1; i <= n; ++ i)
cin >> a[i];
for (long long i = 1; i <= n; ++ i)
cin >> b[i];
}
long long useda[MAXN], needb[MAXN];
bool check(long long x)
{
memset(useda, 0, sizeof(useda));
memset(needb, 0, sizeof(needb));
long long suma = 0, sumb = 0;
for (long long i = 1; i <= n; ++ i)
{
if(a[i] > b[i])
{
long long times = x / a[i];
if(x % a[i] != 0)times ++;
times = min(m, times);
useda[i] = times;
long long ost = max(1LL * 0, x - times * a[i]);
needb[i] = ost / b[i];
if(ost % b[i] != 0)needb[i] ++;
}
else
{
needb[i] = x / b[i];
if(x % b[i] != 0)needb[i] ++;
}
suma += useda[i];
sumb += needb[i];
if(suma + sumb > n * m)return false;
}
return (sumb <= n * m - suma);
}
void solve()
{
long long l = 0, r = 1e18, mid, ans = 0;
while(l <= r)
{
mid = (r - l + 1)/ 2 + l;
if(check(mid))
{
ans = mid;
l = mid + 1LL * 1;
}
else r = mid - 1LL * 1;
}
cout << ans << endl;
}
int main()
{
speed();
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4948 KB |
Output is correct |
2 |
Correct |
7 ms |
4948 KB |
Output is correct |
3 |
Correct |
6 ms |
5036 KB |
Output is correct |
4 |
Correct |
6 ms |
5032 KB |
Output is correct |
5 |
Correct |
6 ms |
4948 KB |
Output is correct |
6 |
Correct |
6 ms |
4948 KB |
Output is correct |
7 |
Correct |
6 ms |
4948 KB |
Output is correct |
8 |
Correct |
6 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
8 ms |
5096 KB |
Output is correct |
11 |
Correct |
97 ms |
9700 KB |
Output is correct |
12 |
Correct |
104 ms |
9772 KB |
Output is correct |
13 |
Correct |
74 ms |
9684 KB |
Output is correct |
14 |
Correct |
64 ms |
9640 KB |
Output is correct |
15 |
Correct |
7 ms |
5032 KB |
Output is correct |
16 |
Correct |
34 ms |
9644 KB |
Output is correct |
17 |
Correct |
85 ms |
9568 KB |
Output is correct |
18 |
Correct |
86 ms |
9672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5032 KB |
Output is correct |
2 |
Correct |
34 ms |
9644 KB |
Output is correct |
3 |
Correct |
85 ms |
9568 KB |
Output is correct |
4 |
Correct |
86 ms |
9672 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
6 |
Correct |
7 ms |
5032 KB |
Output is correct |
7 |
Correct |
7 ms |
4948 KB |
Output is correct |
8 |
Correct |
6 ms |
5032 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
6 ms |
5032 KB |
Output is correct |
11 |
Correct |
6 ms |
4948 KB |
Output is correct |
12 |
Correct |
6 ms |
4948 KB |
Output is correct |
13 |
Correct |
48 ms |
7364 KB |
Output is correct |
14 |
Correct |
34 ms |
6484 KB |
Output is correct |
15 |
Correct |
26 ms |
6196 KB |
Output is correct |
16 |
Correct |
25 ms |
5848 KB |
Output is correct |
17 |
Correct |
7 ms |
5040 KB |
Output is correct |
18 |
Correct |
7 ms |
4948 KB |
Output is correct |
19 |
Correct |
6 ms |
4948 KB |
Output is correct |
20 |
Correct |
6 ms |
4948 KB |
Output is correct |
21 |
Correct |
6 ms |
4948 KB |
Output is correct |
22 |
Correct |
7 ms |
5076 KB |
Output is correct |
23 |
Correct |
9 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4948 KB |
Output is correct |
2 |
Correct |
7 ms |
4948 KB |
Output is correct |
3 |
Correct |
6 ms |
5036 KB |
Output is correct |
4 |
Correct |
6 ms |
5032 KB |
Output is correct |
5 |
Correct |
6 ms |
4948 KB |
Output is correct |
6 |
Correct |
6 ms |
4948 KB |
Output is correct |
7 |
Correct |
6 ms |
4948 KB |
Output is correct |
8 |
Correct |
6 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
8 ms |
5096 KB |
Output is correct |
11 |
Correct |
97 ms |
9700 KB |
Output is correct |
12 |
Correct |
104 ms |
9772 KB |
Output is correct |
13 |
Correct |
74 ms |
9684 KB |
Output is correct |
14 |
Correct |
64 ms |
9640 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
7 ms |
5032 KB |
Output is correct |
17 |
Correct |
7 ms |
4948 KB |
Output is correct |
18 |
Correct |
6 ms |
5032 KB |
Output is correct |
19 |
Correct |
6 ms |
4948 KB |
Output is correct |
20 |
Correct |
6 ms |
5032 KB |
Output is correct |
21 |
Correct |
6 ms |
4948 KB |
Output is correct |
22 |
Correct |
6 ms |
4948 KB |
Output is correct |
23 |
Correct |
48 ms |
7364 KB |
Output is correct |
24 |
Correct |
34 ms |
6484 KB |
Output is correct |
25 |
Correct |
26 ms |
6196 KB |
Output is correct |
26 |
Correct |
25 ms |
5848 KB |
Output is correct |
27 |
Correct |
7 ms |
5040 KB |
Output is correct |
28 |
Correct |
7 ms |
4948 KB |
Output is correct |
29 |
Correct |
6 ms |
4948 KB |
Output is correct |
30 |
Correct |
6 ms |
4948 KB |
Output is correct |
31 |
Correct |
6 ms |
4948 KB |
Output is correct |
32 |
Correct |
7 ms |
5076 KB |
Output is correct |
33 |
Correct |
9 ms |
5076 KB |
Output is correct |
34 |
Correct |
7 ms |
5032 KB |
Output is correct |
35 |
Correct |
34 ms |
9644 KB |
Output is correct |
36 |
Correct |
85 ms |
9568 KB |
Output is correct |
37 |
Correct |
86 ms |
9672 KB |
Output is correct |
38 |
Correct |
7 ms |
5032 KB |
Output is correct |
39 |
Correct |
7 ms |
4948 KB |
Output is correct |
40 |
Correct |
7 ms |
5028 KB |
Output is correct |
41 |
Correct |
6 ms |
4948 KB |
Output is correct |
42 |
Correct |
6 ms |
5028 KB |
Output is correct |
43 |
Correct |
7 ms |
4948 KB |
Output is correct |
44 |
Correct |
6 ms |
5032 KB |
Output is correct |
45 |
Correct |
9 ms |
5008 KB |
Output is correct |
46 |
Correct |
9 ms |
5076 KB |
Output is correct |
47 |
Correct |
7 ms |
5052 KB |
Output is correct |
48 |
Correct |
24 ms |
5708 KB |
Output is correct |
49 |
Correct |
6 ms |
5036 KB |
Output is correct |
50 |
Correct |
7 ms |
4948 KB |
Output is correct |
51 |
Correct |
8 ms |
5104 KB |
Output is correct |
52 |
Correct |
7 ms |
4948 KB |
Output is correct |
53 |
Correct |
7 ms |
4948 KB |
Output is correct |
54 |
Correct |
7 ms |
4948 KB |
Output is correct |
55 |
Correct |
54 ms |
7224 KB |
Output is correct |
56 |
Correct |
32 ms |
6480 KB |
Output is correct |
57 |
Correct |
28 ms |
6592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
5032 KB |
Output is correct |
3 |
Correct |
7 ms |
4948 KB |
Output is correct |
4 |
Correct |
6 ms |
5032 KB |
Output is correct |
5 |
Correct |
6 ms |
4948 KB |
Output is correct |
6 |
Correct |
6 ms |
5032 KB |
Output is correct |
7 |
Correct |
6 ms |
4948 KB |
Output is correct |
8 |
Correct |
6 ms |
4948 KB |
Output is correct |
9 |
Correct |
48 ms |
7364 KB |
Output is correct |
10 |
Correct |
34 ms |
6484 KB |
Output is correct |
11 |
Correct |
26 ms |
6196 KB |
Output is correct |
12 |
Correct |
25 ms |
5848 KB |
Output is correct |
13 |
Correct |
7 ms |
5040 KB |
Output is correct |
14 |
Correct |
7 ms |
4948 KB |
Output is correct |
15 |
Correct |
6 ms |
4948 KB |
Output is correct |
16 |
Correct |
6 ms |
4948 KB |
Output is correct |
17 |
Correct |
6 ms |
4948 KB |
Output is correct |
18 |
Correct |
7 ms |
5076 KB |
Output is correct |
19 |
Correct |
9 ms |
5076 KB |
Output is correct |
20 |
Correct |
7 ms |
5032 KB |
Output is correct |
21 |
Correct |
34 ms |
9644 KB |
Output is correct |
22 |
Correct |
85 ms |
9568 KB |
Output is correct |
23 |
Correct |
86 ms |
9672 KB |
Output is correct |
24 |
Correct |
32 ms |
5640 KB |
Output is correct |
25 |
Correct |
69 ms |
7112 KB |
Output is correct |
26 |
Correct |
17 ms |
5524 KB |
Output is correct |
27 |
Correct |
87 ms |
9584 KB |
Output is correct |
28 |
Correct |
98 ms |
9696 KB |
Output is correct |
29 |
Correct |
95 ms |
9664 KB |
Output is correct |
30 |
Correct |
115 ms |
9696 KB |
Output is correct |
31 |
Correct |
183 ms |
9688 KB |
Output is correct |
32 |
Correct |
109 ms |
9640 KB |
Output is correct |
33 |
Correct |
211 ms |
9808 KB |
Output is correct |
34 |
Correct |
113 ms |
10872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4948 KB |
Output is correct |
2 |
Correct |
7 ms |
4948 KB |
Output is correct |
3 |
Correct |
6 ms |
5036 KB |
Output is correct |
4 |
Correct |
6 ms |
5032 KB |
Output is correct |
5 |
Correct |
6 ms |
4948 KB |
Output is correct |
6 |
Correct |
6 ms |
4948 KB |
Output is correct |
7 |
Correct |
6 ms |
4948 KB |
Output is correct |
8 |
Correct |
6 ms |
4948 KB |
Output is correct |
9 |
Correct |
6 ms |
4948 KB |
Output is correct |
10 |
Correct |
8 ms |
5096 KB |
Output is correct |
11 |
Correct |
97 ms |
9700 KB |
Output is correct |
12 |
Correct |
104 ms |
9772 KB |
Output is correct |
13 |
Correct |
74 ms |
9684 KB |
Output is correct |
14 |
Correct |
64 ms |
9640 KB |
Output is correct |
15 |
Correct |
7 ms |
4992 KB |
Output is correct |
16 |
Correct |
7 ms |
5032 KB |
Output is correct |
17 |
Correct |
7 ms |
4948 KB |
Output is correct |
18 |
Correct |
6 ms |
5032 KB |
Output is correct |
19 |
Correct |
6 ms |
4948 KB |
Output is correct |
20 |
Correct |
6 ms |
5032 KB |
Output is correct |
21 |
Correct |
6 ms |
4948 KB |
Output is correct |
22 |
Correct |
6 ms |
4948 KB |
Output is correct |
23 |
Correct |
48 ms |
7364 KB |
Output is correct |
24 |
Correct |
34 ms |
6484 KB |
Output is correct |
25 |
Correct |
26 ms |
6196 KB |
Output is correct |
26 |
Correct |
25 ms |
5848 KB |
Output is correct |
27 |
Correct |
7 ms |
5040 KB |
Output is correct |
28 |
Correct |
7 ms |
4948 KB |
Output is correct |
29 |
Correct |
6 ms |
4948 KB |
Output is correct |
30 |
Correct |
6 ms |
4948 KB |
Output is correct |
31 |
Correct |
6 ms |
4948 KB |
Output is correct |
32 |
Correct |
7 ms |
5076 KB |
Output is correct |
33 |
Correct |
9 ms |
5076 KB |
Output is correct |
34 |
Correct |
7 ms |
5032 KB |
Output is correct |
35 |
Correct |
7 ms |
4948 KB |
Output is correct |
36 |
Correct |
7 ms |
5028 KB |
Output is correct |
37 |
Correct |
6 ms |
4948 KB |
Output is correct |
38 |
Correct |
6 ms |
5028 KB |
Output is correct |
39 |
Correct |
7 ms |
4948 KB |
Output is correct |
40 |
Correct |
6 ms |
5032 KB |
Output is correct |
41 |
Correct |
9 ms |
5008 KB |
Output is correct |
42 |
Correct |
9 ms |
5076 KB |
Output is correct |
43 |
Correct |
7 ms |
5052 KB |
Output is correct |
44 |
Correct |
24 ms |
5708 KB |
Output is correct |
45 |
Correct |
6 ms |
5036 KB |
Output is correct |
46 |
Correct |
7 ms |
4948 KB |
Output is correct |
47 |
Correct |
8 ms |
5104 KB |
Output is correct |
48 |
Correct |
7 ms |
4948 KB |
Output is correct |
49 |
Correct |
7 ms |
4948 KB |
Output is correct |
50 |
Correct |
7 ms |
4948 KB |
Output is correct |
51 |
Correct |
54 ms |
7224 KB |
Output is correct |
52 |
Correct |
32 ms |
6480 KB |
Output is correct |
53 |
Correct |
28 ms |
6592 KB |
Output is correct |
54 |
Correct |
32 ms |
5640 KB |
Output is correct |
55 |
Correct |
69 ms |
7112 KB |
Output is correct |
56 |
Correct |
17 ms |
5524 KB |
Output is correct |
57 |
Correct |
87 ms |
9584 KB |
Output is correct |
58 |
Correct |
98 ms |
9696 KB |
Output is correct |
59 |
Correct |
95 ms |
9664 KB |
Output is correct |
60 |
Correct |
115 ms |
9696 KB |
Output is correct |
61 |
Correct |
183 ms |
9688 KB |
Output is correct |
62 |
Correct |
109 ms |
9640 KB |
Output is correct |
63 |
Correct |
211 ms |
9808 KB |
Output is correct |
64 |
Correct |
113 ms |
10872 KB |
Output is correct |
65 |
Correct |
7 ms |
5032 KB |
Output is correct |
66 |
Correct |
34 ms |
9644 KB |
Output is correct |
67 |
Correct |
85 ms |
9568 KB |
Output is correct |
68 |
Correct |
86 ms |
9672 KB |
Output is correct |
69 |
Correct |
27 ms |
6124 KB |
Output is correct |
70 |
Correct |
12 ms |
5308 KB |
Output is correct |
71 |
Correct |
6 ms |
4948 KB |
Output is correct |
72 |
Correct |
36 ms |
6540 KB |
Output is correct |
73 |
Correct |
12 ms |
5332 KB |
Output is correct |
74 |
Correct |
7 ms |
4948 KB |
Output is correct |
75 |
Correct |
108 ms |
15504 KB |
Output is correct |
76 |
Correct |
124 ms |
15528 KB |
Output is correct |
77 |
Correct |
130 ms |
15504 KB |
Output is correct |
78 |
Correct |
159 ms |
15516 KB |
Output is correct |
79 |
Correct |
212 ms |
15384 KB |
Output is correct |
80 |
Correct |
214 ms |
15436 KB |
Output is correct |
81 |
Correct |
201 ms |
13460 KB |
Output is correct |
82 |
Correct |
204 ms |
13524 KB |
Output is correct |