This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
using namespace std;
const int64_t INF = (int64_t) 1e18;
const int64_t mINF = (int64_t) 1e9 + 7;
const int64_t MOD = 998244353;
const int nbit = 11;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up
struct Solution
{
int n;
int64_t m;
vector<int64_t> a;
vector<int64_t> b;
vector<int64_t> c;
Solution() {}
void solve()
{
cin >> n >> m;
a.resize(n);
b.resize(n);
c.resize(n);
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
for(int i = 0; i < n; i++)
{
cin >> b[i];
if(b[i] > a[i]) a[i] = b[i];
c[i] = a[i] * m;
}
int64_t ans = INF;
int64_t l = 1;
int64_t r = INF;
while(l <= r)
{
int64_t mid = l + (r - l) / 2;
if(check(mid))
{
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << ans << "\n";
}
bool check(int64_t mid)
{
int64_t cnt = 0;
for(int i = 0; i < n; i++)
{
if(c[i] < mid) continue;
int64_t val = c[i] - mid;
cnt += val / a[i];
}
for(int i = 0; i < n; i++)
{
if(c[i] >= mid) continue;
int64_t val = mid - c[i];
int64_t need = (val + b[i] - 1) / b[i];
if(cnt < need) return false;
cnt -= need;
}
return true;
}
int modsub(int t1, int t2)
{
int res = t1 - t2;
if(res < 0) res += MOD;
return res;
}
int modadd(int t1, int t2)
{
int res = t1 + t2;
if(res >= MOD) res -= MOD;
return res;
}
int modmul(int t1, int t2)
{
int64_t res = 1LL * t1 * t2;
return (res % MOD);
}
bool BIT(int& mask, int& j)
{
return (mask & MASK(j));
}
int MASK(int j)
{
return (1 << j);
}
};
void __startup()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
}
int main()
{
__startup();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
Solution().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... |