#include <iostream>
#include <vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
long long A[300050], B[300050];
void db(){
cout << "\n";
}
template<class T, class ...U>
void db(T XXX, U ...YYY){
cout << XXX << " "; db(YYY...);
}
int main(){
// ios::sync_with_stdio(false); cin.tie(0);
long long N, M;
cin >> N >> M;
loop(i,0,N) cin >> A[i];
loop(i,0,N) cin >> B[i];
loop(i,0,N) C[i] = max(A[i], B[i]);
long long ok = 0, ng = 1LL << 60;
auto check = [&](long long x) -> bool {
long long day = 0, cost, day_test = 0;
loop(i,0,N){
if(x <= C[i] * M) day += (x - 1) / C[i] + 1;
else day += M + (x - C[i] * M - 1) / B[i] + 1;
cost = x;
cost -= min(((cost-1) / C[i] + 1), M) * C[i];
day_test += min(((cost-1) / C[i] + 1), M);
if(cost > 0)
day_test += ((cost-1) / B[i] + 1);
//if(day != day_test) exit(0);
if(day > N * M) return 0;
}
return 1;
};
while(ng - ok > 1){
//db();
long long mid = (ng + ok) / 2;
if(check(mid)) ok = mid;
else ng = mid;
}
cout << ok << endl;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:21:17: error: 'C' was not declared in this scope
21 | loop(i,0,N) C[i] = max(A[i], B[i]);
| ^
Main.cpp: In lambda function:
Main.cpp:27:21: error: 'C' was not declared in this scope
27 | if(x <= C[i] * M) day += (x - 1) / C[i] + 1;
| ^
Main.cpp:31:37: error: 'C' was not declared in this scope
31 | cost -= min(((cost-1) / C[i] + 1), M) * C[i];
| ^