#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define endl '\n'
#define f first
#define s second
#define pb(x) push_back(x)
#define int long long
const int MOD = 1e9+7;
const int inf =1e9;
const ll INF = 1e18;
const ll INV2 = 500000004;
class DSU {
vector<int> parent, size;
public:
DSU(int n) {
parent.resize(n+1);
size.resize(n+1);
for (int i=0; i<=n; i++) {
parent[i]=i;
size[i]=1;
}
}
int find (int node) {
if (node==parent[node]) return node;
return parent[node]=find(parent[node]);
}
void unite (int u, int v) {
int pv=find(v);
int pu=find(u);
if (pv==pu) return;
if (size[pu]<size[pv]) swap(pu, pv);
parent[pv]=pu;
size[pu]+=size[pv];
}
int getsize (int node) {
return size[find(node)];
}
};
ll getsqrt(ll x) {
ll val = sqrtl(x) + 2;
while (val * val > x) val--;
return val;
}
bool safe (int i, int j, int n, int m) {
if (i<0 || j<0 || i>=n || j>=m) return false;
return true;
}
ll gcd(ll a, ll b) {
while (b != 0) {
ll temp=b;
b=a%b;
a=temp;
}
return a;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b)*b;
}
vector<int> dx={-1, 0, 1, 0};
vector<int> dy={0, 1, 0, -1};
// SOLUTION STARTS FROM HERE //
bool check (int x, int n, int m, vector<int> &a, vector<int>&b) {
int tn = 0;
int ta = n*m;
for (int i=0; i<n; i++) {
int slots =0;
int best = max(a[i], b[i]);
if (x<=m*best) {
slots = (x+best-1)/best;
} else {
int rem = x-m*best;
slots = m+(rem+b[i]-1)/b[i];
}
tn+=slots;
if (tn>ta) return false;
}
return tn<=ta;
}
void solve() {
int n, m;
cin>>n>>m;
vector<int> a(n);
for (int i=0; i<n; i++) {
cin>>a[i];
}
vector<int> b(n);
for (int i=0; i<n; i++) {
cin>>b[i];
}
int l=0, r=1e18;
int ans=0;
while (l<=r) {
int mid = l+(r-l)/2;
if (check(mid, n, m, a, b)) {
ans=max(ans, mid);
l=mid+1;
} else {
r=mid-1;
}
}
cout<<ans<<endl;
// m=1, only one weak
/*
for subject i, if he studies ith subject in class x times
and by himself y times then his score will be:
x[i]*a[i] + y[i]+b[i]; we need to maximise the minimum value
of this
*/
}
bool multi=false;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("convention2.in", "r", stdin);
//freopen("convention2.out", "w", stdout);
int t=1;
if (multi) cin>>t;
while (t--) solve();
return 0;
}
| # | 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... |