#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MAX = 2e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m;
cin >> n >> m;
ll a[n + 1];
for(ll i = 1; i <= n; ++i){
cin >> a[i];
}
ll b[n + 1];
for(ll i = 1; i <= n; ++i){
cin >> b[i];
}
ll L = 0;
ll R = MAX;
while(R - L > 1){
ll mid = (L + R) >> 1;
ll can = 0ll;
ll need = 0ll;
for(ll i = 1; i <= n; ++i){
ll cur = (mid / max(a[i], b[i]) );
if(mid % (max(a[i], b[i])) != 0) cur++;
if(cur > m){
cur -= ( (cur - m) );
ll ost = (mid - (m * max(a[i], b[i]) ) );
cur += (ost / b[i]);
if((ost % b[i]) != 0ll) cur++;
}
if(cur < m){
can += (m - cur);
}
if(cur > m){
need += (cur - m);
}
}
if(need <= can){
L = mid;
}
else{
R = mid;
}
}
cout << L << endl;
return 0;
// 1000 * 1000 | 33 ?
}
# |
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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
112 ms |
4928 KB |
Output is correct |
12 |
Correct |
108 ms |
4952 KB |
Output is correct |
13 |
Correct |
107 ms |
4956 KB |
Output is correct |
14 |
Incorrect |
128 ms |
4944 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 |
428 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 |
57 ms |
2648 KB |
Output is correct |
10 |
Correct |
38 ms |
2004 KB |
Output is correct |
11 |
Correct |
28 ms |
1628 KB |
Output is correct |
12 |
Correct |
23 ms |
1616 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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
2 ms |
348 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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
112 ms |
4928 KB |
Output is correct |
12 |
Correct |
108 ms |
4952 KB |
Output is correct |
13 |
Correct |
107 ms |
4956 KB |
Output is correct |
14 |
Incorrect |
128 ms |
4944 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 |
428 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 |
57 ms |
2648 KB |
Output is correct |
10 |
Correct |
38 ms |
2004 KB |
Output is correct |
11 |
Correct |
28 ms |
1628 KB |
Output is correct |
12 |
Correct |
23 ms |
1616 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 |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
2 ms |
348 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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
112 ms |
4928 KB |
Output is correct |
12 |
Correct |
108 ms |
4952 KB |
Output is correct |
13 |
Correct |
107 ms |
4956 KB |
Output is correct |
14 |
Incorrect |
128 ms |
4944 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |