# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1181846 | SmuggingSpun | Self Study (JOI22_ho_t2) | C++20 | 129 ms | 2788 KiB |
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
const int INF = 2e9;
int n, m;
namespace sub1{
void solve(){
vector<int>a(n);
for(int& x : a){
cin >> x;
}
int ans = INF;
for(int i = 0; i < n; i++){
int x;
cin >> x;
minimize(ans, max(x, a[i]));
}
cout << ans;
}
}
namespace sub2345{
const int lim = 3e5 + 5;
int a[lim], b[lim];
void solve(){
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> b[i];
}
ll low = 1, high = 1e18, ans = 0;
while(low <= high){
ll mid = (low + high) >> 1LL, cnt = 0;
for(int i = 1; i <= n; i++){
if(a[i] > b[i]){
int coef = min(ll(m), (mid - 1) / a[i] + 1);
cnt += coef;
ll remain = mid - 1LL * coef * a[i];
if(remain > 0){
cnt += (remain - 1) / b[i] + 1;
}
}
else{
cnt += (mid - 1) / b[i] + 1;
}
}
if(cnt > 1LL * n * m){
high = mid - 1;
}
else{
low = (ans = mid) + 1;
}
}
cout << ans;
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> m;
if(m == 1 && false){
sub1::solve();
}
else{
sub2345::solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |