#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
vector<pair<int,int>> v;
int n,m;
bool check(int mid){
vector<int> need(n);
int left = 0;
for(int i = 0; i<n; i++){
int z = max(v[i].first, v[i].second);
int k = (mid+z-1)/z;
if(k > m) need[i] = mid-(m * z);
else left+=m-k;
}
for(int i = 0; i<n; i++){
left -= (need[i] + v[i].second - 1)/v[i].second;
}
return left>=0;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
v.resize(n);
for(auto& x : v) cin>>x.first;
for(auto& x : v) cin>>x.second;
int ans = LLONG_MAX;
for(auto i : v){
ans = min(ans,max(i.first,i.second));
}
cout<<ans<<endl;
return 0;
int l = 0; int r = 1e18;
while(r > l+1){
int mid = (l+r)/2;
if(check(mid)) l = mid;
else r = mid;
}
cout<<l<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
45 ms |
4956 KB |
Output is correct |
12 |
Correct |
45 ms |
4952 KB |
Output is correct |
13 |
Correct |
35 ms |
4952 KB |
Output is correct |
14 |
Correct |
35 ms |
4956 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
23 ms |
5148 KB |
Output is correct |
17 |
Correct |
46 ms |
4956 KB |
Output is correct |
18 |
Correct |
44 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
23 ms |
5148 KB |
Output is correct |
3 |
Correct |
46 ms |
4956 KB |
Output is correct |
4 |
Correct |
44 ms |
4956 KB |
Output is correct |
5 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
45 ms |
4956 KB |
Output is correct |
12 |
Correct |
45 ms |
4952 KB |
Output is correct |
13 |
Correct |
35 ms |
4952 KB |
Output is correct |
14 |
Correct |
35 ms |
4956 KB |
Output is correct |
15 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
45 ms |
4956 KB |
Output is correct |
12 |
Correct |
45 ms |
4952 KB |
Output is correct |
13 |
Correct |
35 ms |
4952 KB |
Output is correct |
14 |
Correct |
35 ms |
4956 KB |
Output is correct |
15 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |