#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define what(x) cout << (#x) << " -> " << x << '\n';
#define endl '\n'
#define cno cout << "NO" \
<< "\n"
#define cy cout << "YES" \
<< "\n"
#define c1 cout << "-1" << '\n'
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const ll N = 1000005;
const ll mod = 1000000007;
ll n, m, k, l, r, q, d, x, y, z, id, ind, pointer, point, next, curr, temp;
ll mn = 2e18, mx = 0, Maxmx = 0, Ans = 0, cost = 0, prod = 1, tot = 0, sum = 0;
ll a[N], arr[N], b[N];
vector<ll> v;
string s, t;
bool ok(ll mid)
{
ll ans = 0;
for (int i = 1; i <= n; i++)
{
temp = mid;
x = (temp + max(a[i], b[i]) - 1) / max(a[i], b[i]);
temp -= min(min(m, x) * max(a[i], b[i]), temp);
y = (temp + b[i] - 1) / b[i];
ans += min(x, m) + y;
}
if (ans <= ll(m * n))
return 1;
return 0;
}
void solve()
{
cin >> n >> m;
x = 1;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
cin >> b[i];
}
ll lo = 1, hi = 1e12;
while (ok(hi))
hi *= 2;
while (lo < hi)
{
ll mid = (lo + hi + 1) / 2;
if (ok(mid))
lo = mid;
else
hi = mid - 1;
}
cout << lo << endl;
}
int main()
{
IOS int testcases = 1;
// cin >> testcases;
while (testcases--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
155 ms |
8836 KB |
Output is correct |
12 |
Correct |
157 ms |
8828 KB |
Output is correct |
13 |
Correct |
146 ms |
8824 KB |
Output is correct |
14 |
Correct |
170 ms |
8828 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
197 ms |
8852 KB |
Output is correct |
17 |
Correct |
160 ms |
8824 KB |
Output is correct |
18 |
Correct |
159 ms |
8828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
197 ms |
8852 KB |
Output is correct |
3 |
Correct |
160 ms |
8824 KB |
Output is correct |
4 |
Correct |
159 ms |
8828 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
77 ms |
6748 KB |
Output is correct |
14 |
Correct |
52 ms |
4740 KB |
Output is correct |
15 |
Correct |
39 ms |
4696 KB |
Output is correct |
16 |
Correct |
32 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
4 ms |
2396 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
155 ms |
8836 KB |
Output is correct |
12 |
Correct |
157 ms |
8828 KB |
Output is correct |
13 |
Correct |
146 ms |
8824 KB |
Output is correct |
14 |
Correct |
170 ms |
8828 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
77 ms |
6748 KB |
Output is correct |
24 |
Correct |
52 ms |
4740 KB |
Output is correct |
25 |
Correct |
39 ms |
4696 KB |
Output is correct |
26 |
Correct |
32 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
4 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
197 ms |
8852 KB |
Output is correct |
36 |
Correct |
160 ms |
8824 KB |
Output is correct |
37 |
Correct |
159 ms |
8828 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 |
1 ms |
2396 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 |
3 ms |
2396 KB |
Output is correct |
46 |
Correct |
5 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
30 ms |
4748 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
3 ms |
2396 KB |
Output is correct |
52 |
Correct |
0 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2392 KB |
Output is correct |
54 |
Correct |
1 ms |
2392 KB |
Output is correct |
55 |
Correct |
77 ms |
6748 KB |
Output is correct |
56 |
Correct |
53 ms |
4696 KB |
Output is correct |
57 |
Correct |
58 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
77 ms |
6748 KB |
Output is correct |
10 |
Correct |
52 ms |
4740 KB |
Output is correct |
11 |
Correct |
39 ms |
4696 KB |
Output is correct |
12 |
Correct |
32 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
4 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
197 ms |
8852 KB |
Output is correct |
22 |
Correct |
160 ms |
8824 KB |
Output is correct |
23 |
Correct |
159 ms |
8828 KB |
Output is correct |
24 |
Correct |
42 ms |
4700 KB |
Output is correct |
25 |
Correct |
98 ms |
6772 KB |
Output is correct |
26 |
Correct |
18 ms |
4700 KB |
Output is correct |
27 |
Correct |
157 ms |
8652 KB |
Output is correct |
28 |
Correct |
159 ms |
9224 KB |
Output is correct |
29 |
Correct |
154 ms |
8788 KB |
Output is correct |
30 |
Correct |
166 ms |
8836 KB |
Output is correct |
31 |
Correct |
307 ms |
8828 KB |
Output is correct |
32 |
Correct |
211 ms |
8660 KB |
Output is correct |
33 |
Correct |
362 ms |
8832 KB |
Output is correct |
34 |
Correct |
218 ms |
8788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
155 ms |
8836 KB |
Output is correct |
12 |
Correct |
157 ms |
8828 KB |
Output is correct |
13 |
Correct |
146 ms |
8824 KB |
Output is correct |
14 |
Correct |
170 ms |
8828 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
77 ms |
6748 KB |
Output is correct |
24 |
Correct |
52 ms |
4740 KB |
Output is correct |
25 |
Correct |
39 ms |
4696 KB |
Output is correct |
26 |
Correct |
32 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
4 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 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 |
3 ms |
2396 KB |
Output is correct |
42 |
Correct |
5 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
30 ms |
4748 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
3 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2392 KB |
Output is correct |
50 |
Correct |
1 ms |
2392 KB |
Output is correct |
51 |
Correct |
77 ms |
6748 KB |
Output is correct |
52 |
Correct |
53 ms |
4696 KB |
Output is correct |
53 |
Correct |
58 ms |
4700 KB |
Output is correct |
54 |
Correct |
42 ms |
4700 KB |
Output is correct |
55 |
Correct |
98 ms |
6772 KB |
Output is correct |
56 |
Correct |
18 ms |
4700 KB |
Output is correct |
57 |
Correct |
157 ms |
8652 KB |
Output is correct |
58 |
Correct |
159 ms |
9224 KB |
Output is correct |
59 |
Correct |
154 ms |
8788 KB |
Output is correct |
60 |
Correct |
166 ms |
8836 KB |
Output is correct |
61 |
Correct |
307 ms |
8828 KB |
Output is correct |
62 |
Correct |
211 ms |
8660 KB |
Output is correct |
63 |
Correct |
362 ms |
8832 KB |
Output is correct |
64 |
Correct |
218 ms |
8788 KB |
Output is correct |
65 |
Correct |
1 ms |
2396 KB |
Output is correct |
66 |
Correct |
197 ms |
8852 KB |
Output is correct |
67 |
Correct |
160 ms |
8824 KB |
Output is correct |
68 |
Correct |
159 ms |
8828 KB |
Output is correct |
69 |
Correct |
31 ms |
4696 KB |
Output is correct |
70 |
Correct |
9 ms |
2524 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
48 ms |
4700 KB |
Output is correct |
73 |
Correct |
9 ms |
2396 KB |
Output is correct |
74 |
Correct |
1 ms |
2396 KB |
Output is correct |
75 |
Correct |
156 ms |
8788 KB |
Output is correct |
76 |
Correct |
173 ms |
8828 KB |
Output is correct |
77 |
Correct |
164 ms |
8828 KB |
Output is correct |
78 |
Correct |
219 ms |
8788 KB |
Output is correct |
79 |
Correct |
317 ms |
8828 KB |
Output is correct |
80 |
Correct |
339 ms |
8832 KB |
Output is correct |
81 |
Correct |
351 ms |
8856 KB |
Output is correct |
82 |
Incorrect |
521 ms |
8836 KB |
Output isn't correct |
83 |
Halted |
0 ms |
0 KB |
- |