/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6, M = 1e5+10, K = 20;
ll n, m, c, ls, rs, s, mn = 1e18;
array<ll, 2> a[N];
vector<array<ll, 2>> lt, rt;
void solve(){
cin >> n >> m;
for(int i = 0; i < n; ++i) cin >> a[i][0];
for(int i = 0; i < n; ++i) cin >> a[i][1];
for(int i = 0; i < n; ++i){
if(a[i][0] >= a[i][1])
lt.pb(a[i]);
else
rt.pb(a[i]);
mn = min(a[i][0], mn);
}
ls = lt.size();
rs = rt.size();
ll l = 1, r = 2e18, ans = mn;
while(l <= r){
ll mid = (l+r) >> 1;
s = 0;
for(int i = 0; i < ls; ++i){
c = (mid + lt[i][0] - 1) / lt[i][0];
if(c > m){
s -= (mid - lt[i][0] * m + (lt[i][1] - 1)) / lt[i][1];
}else{
s += m - c;
}
}
for(int i = 0; i < rs; ++i){
if(mid - m * rt[i][1] > 0){
s -= (mid - m * rt[i][1] + (rt[i][1] - 1)) / rt[i][1];
}else{
s += m - (mid + rt[i][1] - 1) / rt[i][1];
}
}
if(s >= 0){
l = mid + 1;
ans = mid;
}else{
r = mid - 1;
}
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:70:14: warning: unused variable 'aa' [-Wunused-variable]
70 | int T = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
235 ms |
11260 KB |
Output is correct |
12 |
Correct |
207 ms |
11376 KB |
Output is correct |
13 |
Correct |
176 ms |
13248 KB |
Output is correct |
14 |
Incorrect |
485 ms |
13376 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
127 ms |
6884 KB |
Output is correct |
10 |
Correct |
90 ms |
4060 KB |
Output is correct |
11 |
Correct |
62 ms |
3664 KB |
Output is correct |
12 |
Correct |
48 ms |
2332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
9 ms |
596 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
235 ms |
11260 KB |
Output is correct |
12 |
Correct |
207 ms |
11376 KB |
Output is correct |
13 |
Correct |
176 ms |
13248 KB |
Output is correct |
14 |
Incorrect |
485 ms |
13376 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
127 ms |
6884 KB |
Output is correct |
10 |
Correct |
90 ms |
4060 KB |
Output is correct |
11 |
Correct |
62 ms |
3664 KB |
Output is correct |
12 |
Correct |
48 ms |
2332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
9 ms |
596 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
235 ms |
11260 KB |
Output is correct |
12 |
Correct |
207 ms |
11376 KB |
Output is correct |
13 |
Correct |
176 ms |
13248 KB |
Output is correct |
14 |
Incorrect |
485 ms |
13376 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |