#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int __int128
#define pii pair<int,int>
#define p_q priority_queue
#define endl '\n'
#define pb push_back
long long N, M;
int n, m;
const int one = 1, two = 2, zero = 0;
vector<int> a, b;
bool check(int mid) {
int rem = n*m;
for (int i = 0; i < n; ++i) {
if (a[i] > b[i]) {
if (a[i]*m >= mid) {
rem -= mid/a[i]+(mid%a[i] > zero);
} else {
int cur = mid-a[i]*m;
rem -= m;
rem -= cur/b[i]+(cur%b[i] > zero);
}
} else {
rem -= mid/b[i]+(mid%b[i] > zero);
}
}
return rem >= zero;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>N>>M;
n = N, m = M;
a.resize(n), b.resize(n);
for (auto& i : a) {
long long x; cin>>x;
i = x;
}
for (auto& i : b) {
long long x; cin>>x;
i = x;
}
int l = zero, r = 2e36;
while(r-l > one) {
int mid = (l+r)/two;
if (check(mid)) l = mid;
else r = mid;
}
long long ans = l;
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
7 ms |
348 KB |
Output is correct |
11 |
Correct |
515 ms |
9848 KB |
Output is correct |
12 |
Correct |
498 ms |
9816 KB |
Output is correct |
13 |
Correct |
414 ms |
10068 KB |
Output is correct |
14 |
Incorrect |
986 ms |
9852 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
222 ms |
5208 KB |
Output is correct |
10 |
Correct |
143 ms |
3420 KB |
Output is correct |
11 |
Correct |
107 ms |
2652 KB |
Output is correct |
12 |
Correct |
86 ms |
2140 KB |
Output is correct |
13 |
Correct |
1 ms |
544 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
16 ms |
600 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
7 ms |
348 KB |
Output is correct |
11 |
Correct |
515 ms |
9848 KB |
Output is correct |
12 |
Correct |
498 ms |
9816 KB |
Output is correct |
13 |
Correct |
414 ms |
10068 KB |
Output is correct |
14 |
Incorrect |
986 ms |
9852 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
222 ms |
5208 KB |
Output is correct |
10 |
Correct |
143 ms |
3420 KB |
Output is correct |
11 |
Correct |
107 ms |
2652 KB |
Output is correct |
12 |
Correct |
86 ms |
2140 KB |
Output is correct |
13 |
Correct |
1 ms |
544 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
16 ms |
600 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
7 ms |
348 KB |
Output is correct |
11 |
Correct |
515 ms |
9848 KB |
Output is correct |
12 |
Correct |
498 ms |
9816 KB |
Output is correct |
13 |
Correct |
414 ms |
10068 KB |
Output is correct |
14 |
Incorrect |
986 ms |
9852 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |