#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
// #ifndef ONLINE_JUDGE
// #include "E:\Personal\cpp_codes\debugalgo.h"
// #else
// #define debug(x)
// #endif
void solve(int tc)
{
ll n,m;
cin>>n>>m;
vector<pair<ll,ll>> a(n);
for(int i=0; i<n; i++)
{
cin>>a[i].first;
}
for(int i=0; i<n; i++) cin>>a[i].second;
vector<pair<ll,ll>> largerA;
vector<ll> largerB;
for(int i=0; i<n; i++)
{
if(a[i].first>a[i].second)
{
largerA.push_back(a[i]);
}
else
{
largerB.push_back(a[i].second);
}
}
sort(largerA.rbegin(),largerA.rend());
sort(largerB.rbegin(),largerB.rend());
// debug(largerA);
// debug(largerB);
auto feasible = [&](ll mid)
{
ll carry = 0;
for(auto &x: largerB)
{
ll need = (mid + x-1)/x;
carry += (m-need);
}
for(auto &[x,y]: largerA)
{
ll xval = x*m;
if(xval>=mid)
{
carry+= (m - (mid+x-1)/x);
}
else
{
ll need = (mid - x*m + y - 1)/y;
carry -= need;
}
}
return carry>=0;
};
ll l = 0;
ll r = 1e16;
ll ans = 0;
while(l<=r)
{
ll mid = l + (r-l)/2;
if(feasible(mid))
{
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout<<ans<<"\n";
}
int main()
{
ios_base:: sync_with_stdio(0);
cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("Error.txt", "w", stderr);
// #endif
int tt = 1;
// cin >> tt;
for(int tc=1; tc<=tt; tc++)
{
solve(tc);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
154 ms |
17088 KB |
Output is correct |
12 |
Correct |
153 ms |
17592 KB |
Output is correct |
13 |
Correct |
123 ms |
14028 KB |
Output is correct |
14 |
Incorrect |
238 ms |
19456 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
76 ms |
7656 KB |
Output is correct |
10 |
Correct |
51 ms |
5072 KB |
Output is correct |
11 |
Correct |
38 ms |
4164 KB |
Output is correct |
12 |
Correct |
30 ms |
3036 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
154 ms |
17088 KB |
Output is correct |
12 |
Correct |
153 ms |
17592 KB |
Output is correct |
13 |
Correct |
123 ms |
14028 KB |
Output is correct |
14 |
Incorrect |
238 ms |
19456 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
76 ms |
7656 KB |
Output is correct |
10 |
Correct |
51 ms |
5072 KB |
Output is correct |
11 |
Correct |
38 ms |
4164 KB |
Output is correct |
12 |
Correct |
30 ms |
3036 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
154 ms |
17088 KB |
Output is correct |
12 |
Correct |
153 ms |
17592 KB |
Output is correct |
13 |
Correct |
123 ms |
14028 KB |
Output is correct |
14 |
Incorrect |
238 ms |
19456 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |