#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)3e5 + 10;
ll A[N];
ll B[N];
ll ceil(ll x, ll y){
return (x + y - 1) / y;
}
int main(){
fastIO;
//freopen("in.txt","r",stdin);
ll m;
int n;
cin >> n >> m;
for(int i = 1; i <= n; i ++ ){
cin >> A[i];
}
for(int i = 1; i <= n; i ++ ){
cin >> B[i];
}
for(int i = 1; i <= n; i ++ ){
A[i] = max(A[i], B[i]);
}
ll li = 1;
ll ri = (ll)1e17;
ll mid;
ll have = 0;
ll need = 0;
ll take;
ll rem;
while(li + 1 < ri){
mid = (li + ri) / 2;
have = 0;
need = 0;
for(int i = 1; i <= n; i ++ ){
take = ceil(mid, A[i]);
if(take <= m){
have += m - take;
}
else{
rem = mid - A[i] * 1ll * m;
if(rem >= 0) need += ceil(rem, B[i]);
}
}
if(have >= need){
li = mid;
}
else{
ri = mid;
}
}
cout << li << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
400 KB |
Output is correct |
11 |
Correct |
204 ms |
4988 KB |
Output is correct |
12 |
Correct |
233 ms |
4996 KB |
Output is correct |
13 |
Correct |
216 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
426 ms |
5036 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
113 ms |
2656 KB |
Output is correct |
10 |
Correct |
74 ms |
1868 KB |
Output is correct |
11 |
Correct |
55 ms |
1480 KB |
Output is correct |
12 |
Correct |
43 ms |
1248 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Incorrect |
9 ms |
332 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
400 KB |
Output is correct |
11 |
Correct |
204 ms |
4988 KB |
Output is correct |
12 |
Correct |
233 ms |
4996 KB |
Output is correct |
13 |
Correct |
216 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
426 ms |
5036 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
113 ms |
2656 KB |
Output is correct |
10 |
Correct |
74 ms |
1868 KB |
Output is correct |
11 |
Correct |
55 ms |
1480 KB |
Output is correct |
12 |
Correct |
43 ms |
1248 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Incorrect |
9 ms |
332 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
4 ms |
400 KB |
Output is correct |
11 |
Correct |
204 ms |
4988 KB |
Output is correct |
12 |
Correct |
233 ms |
4996 KB |
Output is correct |
13 |
Correct |
216 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
426 ms |
5036 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |