#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const ll linf = 1e18 + 1;
bool check(ll a[], ll b[], ll x, ll n, ll m){
ll cnt = 0;
for(int i = 1; i <= n; i++){
ll cnta;
if(b[i] > a[i])cnta = 0;
else{
cnta = x / a[i];
if(x % a[i]) cnta++;
cnta = min(cnta, m);
}
ll cur = x - a[i] * cnta;
cnt += cnta;
if(cur < 0) continue;
else{
cnt += cur / b[i];
if(cur % b[i])cnt++;
}
}
return cnt <= n * m;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
ll n; cin >> n;
ll m; cin >> m;
ll a[n + 1];
ll b[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> b[i];
}
ll l = 0, r = linf;
while(l + 1 < r){
ll mid = (l + r) / 2;
if(check(a, b, mid, n, m))l = mid;
else r = mid;
}
cout << l;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
207 ms |
10800 KB |
Output is correct |
12 |
Correct |
227 ms |
10804 KB |
Output is correct |
13 |
Correct |
159 ms |
8836 KB |
Output is correct |
14 |
Incorrect |
496 ms |
8812 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
119 ms |
5552 KB |
Output is correct |
10 |
Correct |
85 ms |
3800 KB |
Output is correct |
11 |
Correct |
64 ms |
2868 KB |
Output is correct |
12 |
Correct |
53 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
10 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
207 ms |
10800 KB |
Output is correct |
12 |
Correct |
227 ms |
10804 KB |
Output is correct |
13 |
Correct |
159 ms |
8836 KB |
Output is correct |
14 |
Incorrect |
496 ms |
8812 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
119 ms |
5552 KB |
Output is correct |
10 |
Correct |
85 ms |
3800 KB |
Output is correct |
11 |
Correct |
64 ms |
2868 KB |
Output is correct |
12 |
Correct |
53 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
10 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
207 ms |
10800 KB |
Output is correct |
12 |
Correct |
227 ms |
10804 KB |
Output is correct |
13 |
Correct |
159 ms |
8836 KB |
Output is correct |
14 |
Incorrect |
496 ms |
8812 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |