#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
// #ifndef ONLINE_JUDGE
// #include "E:\Personal\cpp_codes\debugalgo.h"
// #else
// #define debug(x)
// #endif
const ll inf = 1e16;
void solve(int tc)
{
ll n,m;
cin>>n>>m;
ll mx = 0;
vector<pair<ll,ll>> a(n);
for(int i=0; i<n; i++)
{
cin>>a[i].first;
mx = max(mx, a[i].first*m);
}
for(int i=0; i<n; i++) {
cin>>a[i].second;
mx = max(mx,a[i].second*m);
}
vector<pair<ll,ll>> largerA;
vector<ll> largerB;
for(int i=0; i<n; i++)
{
if(a[i].first>a[i].second)
{
largerA.push_back(a[i]);
}
else
{
largerB.push_back(a[i].second);
}
}
auto feasible = [&](ll mid)
{
ll carry = 0;
for(auto &x: largerB)
{
ll need = (mid + x-1)/x;
carry += (m-need);
if(carry<=-inf) return 0;
}
for(auto &[x,y]: largerA)
{
if(m>=(mid+x-1)/x)
{
carry+= (m - (mid+x-1)/x);
}
else
{
ll need = ((mid - x*m) + y - 1)/y;
carry -= need;
if(carry<=-inf) return 0;
}
}
return int(carry>=0);
};
ll l = 1;
ll r = mx;
ll ans = 0;
while(l<=r)
{
ll mid = l + (r-l)/2;
if(feasible(mid))
{
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout<<ans<<"\n";
}
int main()
{
ios_base:: sync_with_stdio(0);
cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("Error.txt", "w", stderr);
// #endif
int tt = 1;
// cin >> tt;
for(int tc=1; tc<=tt; tc++)
{
solve(tc);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
90 ms |
11604 KB |
Output is correct |
12 |
Correct |
90 ms |
11144 KB |
Output is correct |
13 |
Correct |
77 ms |
9372 KB |
Output is correct |
14 |
Correct |
80 ms |
15048 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
11000 KB |
Output is correct |
17 |
Correct |
90 ms |
17412 KB |
Output is correct |
18 |
Correct |
88 ms |
16260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
30 ms |
11000 KB |
Output is correct |
3 |
Correct |
90 ms |
17412 KB |
Output is correct |
4 |
Correct |
88 ms |
16260 KB |
Output is correct |
5 |
Correct |
1 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 |
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 |
44 ms |
4988 KB |
Output is correct |
14 |
Correct |
30 ms |
3036 KB |
Output is correct |
15 |
Correct |
23 ms |
2792 KB |
Output is correct |
16 |
Correct |
19 ms |
2016 KB |
Output is correct |
17 |
Correct |
1 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 |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
90 ms |
11604 KB |
Output is correct |
12 |
Correct |
90 ms |
11144 KB |
Output is correct |
13 |
Correct |
77 ms |
9372 KB |
Output is correct |
14 |
Correct |
80 ms |
15048 KB |
Output is correct |
15 |
Correct |
1 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 |
1 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 |
44 ms |
4988 KB |
Output is correct |
24 |
Correct |
30 ms |
3036 KB |
Output is correct |
25 |
Correct |
23 ms |
2792 KB |
Output is correct |
26 |
Correct |
19 ms |
2016 KB |
Output is correct |
27 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
720 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
30 ms |
11000 KB |
Output is correct |
36 |
Correct |
90 ms |
17412 KB |
Output is correct |
37 |
Correct |
88 ms |
16260 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
452 KB |
Output is correct |
41 |
Correct |
1 ms |
452 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
4 ms |
860 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
17 ms |
3004 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
48 ms |
8144 KB |
Output is correct |
56 |
Correct |
31 ms |
4316 KB |
Output is correct |
57 |
Correct |
29 ms |
5336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 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 |
44 ms |
4988 KB |
Output is correct |
10 |
Correct |
30 ms |
3036 KB |
Output is correct |
11 |
Correct |
23 ms |
2792 KB |
Output is correct |
12 |
Correct |
19 ms |
2016 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
3 ms |
720 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
11000 KB |
Output is correct |
22 |
Correct |
90 ms |
17412 KB |
Output is correct |
23 |
Correct |
88 ms |
16260 KB |
Output is correct |
24 |
Correct |
27 ms |
2528 KB |
Output is correct |
25 |
Correct |
66 ms |
7372 KB |
Output is correct |
26 |
Correct |
12 ms |
1880 KB |
Output is correct |
27 |
Correct |
90 ms |
15380 KB |
Output is correct |
28 |
Correct |
91 ms |
15884 KB |
Output is correct |
29 |
Correct |
98 ms |
16280 KB |
Output is correct |
30 |
Correct |
122 ms |
15820 KB |
Output is correct |
31 |
Correct |
196 ms |
15372 KB |
Output is correct |
32 |
Correct |
102 ms |
11732 KB |
Output is correct |
33 |
Correct |
211 ms |
15888 KB |
Output is correct |
34 |
Correct |
126 ms |
11720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
90 ms |
11604 KB |
Output is correct |
12 |
Correct |
90 ms |
11144 KB |
Output is correct |
13 |
Correct |
77 ms |
9372 KB |
Output is correct |
14 |
Correct |
80 ms |
15048 KB |
Output is correct |
15 |
Correct |
1 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 |
1 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 |
44 ms |
4988 KB |
Output is correct |
24 |
Correct |
30 ms |
3036 KB |
Output is correct |
25 |
Correct |
23 ms |
2792 KB |
Output is correct |
26 |
Correct |
19 ms |
2016 KB |
Output is correct |
27 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
720 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
452 KB |
Output is correct |
37 |
Correct |
1 ms |
452 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
4 ms |
860 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
17 ms |
3004 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
48 ms |
8144 KB |
Output is correct |
52 |
Correct |
31 ms |
4316 KB |
Output is correct |
53 |
Correct |
29 ms |
5336 KB |
Output is correct |
54 |
Correct |
27 ms |
2528 KB |
Output is correct |
55 |
Correct |
66 ms |
7372 KB |
Output is correct |
56 |
Correct |
12 ms |
1880 KB |
Output is correct |
57 |
Correct |
90 ms |
15380 KB |
Output is correct |
58 |
Correct |
91 ms |
15884 KB |
Output is correct |
59 |
Correct |
98 ms |
16280 KB |
Output is correct |
60 |
Correct |
122 ms |
15820 KB |
Output is correct |
61 |
Correct |
196 ms |
15372 KB |
Output is correct |
62 |
Correct |
102 ms |
11732 KB |
Output is correct |
63 |
Correct |
211 ms |
15888 KB |
Output is correct |
64 |
Correct |
126 ms |
11720 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
30 ms |
11000 KB |
Output is correct |
67 |
Correct |
90 ms |
17412 KB |
Output is correct |
68 |
Correct |
88 ms |
16260 KB |
Output is correct |
69 |
Correct |
20 ms |
2004 KB |
Output is correct |
70 |
Correct |
6 ms |
860 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
32 ms |
2688 KB |
Output is correct |
73 |
Correct |
6 ms |
856 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
97 ms |
16568 KB |
Output is correct |
76 |
Correct |
122 ms |
17904 KB |
Output is correct |
77 |
Correct |
118 ms |
17276 KB |
Output is correct |
78 |
Correct |
152 ms |
19016 KB |
Output is correct |
79 |
Correct |
207 ms |
18372 KB |
Output is correct |
80 |
Correct |
214 ms |
17400 KB |
Output is correct |
81 |
Correct |
197 ms |
14468 KB |
Output is correct |
82 |
Correct |
202 ms |
17296 KB |
Output is correct |