#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define what(x) cout << (#x) << " -> " << x << '\n';
#define endl '\n'
#define cno cout << "NO" \
<< "\n"
#define cy cout << "YES" \
<< "\n"
#define c1 cout << "-1" << '\n'
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const ll N = 1000005;
const ll mod = 1000000007;
ll n, m, k, l, r, q, d, x, y, z, id, ind, pointer, point, next, curr, temp;
ll mn = 2e18, mx = 0, Maxmx = 0, Ans = 0, cost = 0, prod = 1, tot = 0, sum = 0;
ll a[N], arr[N], b[N];
vector<ll> v;
string s, t;
bool ok(ll mid)
{
ll ans = 0;
for (int i = 1; i <= n; i++)
{
temp = mid;
x = (temp + max(a[i], b[i]) - 1) / max(a[i], b[i]);
temp -= min(min(m, x) * max(a[i], b[i]), temp);
y = (temp + b[i] - 1) / b[i];
ans += min(x, m) + y;
if (ans <= m * n)
return 1;
}
return 0;
}
void solve()
{
cin >> n >> m;
x = 1;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= n; i++)
{
cin >> b[i];
}
ll lo = 1, hi = 1e9;
while (ok(hi))
hi *= 2;
while (lo < hi)
{
ll mid = (lo + hi + 1) / 2;
if (ok(mid))
lo = mid;
else
hi = mid - 1;
}
cout << lo << endl;
}
int main()
{
IOS int testcases = 1;
// cin >> testcases;
while (testcases--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |