//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
void solve(){
int n, m; cin >> n >> m;
vector<int>a(n+1), b(n+1);
for (int i = 1; i<=n; i++) cin >> a[i];
for (int i = 1; i<=n; i++) cin >> b[i];
for (int i = 1; i<=n; i++) a[i] = max(a[i], b[i]);
auto check = [&](int mid){
vector<int>left(n+1, mid);
int todo = 0, extra = 0;
for (int i = 1; i<=n; i++){
int ile = (mid+a[i]-1)/a[i];
if (ile <= m){
extra += (m-ile);
left[i] = 0;
} else {
left[i] -= m*a[i];
}
}
for (int i = 1; i<=n; i++){
if (left[i] > 0){
int ile = (left[i]+b[i]-1)/b[i];
extra -= ile;
if (extra < 0) return false;
}
}
return true;
};
int l = 0, r = oo, ans = 0;
while (r >= l){
int mid = (l+r)/2;
if (check(mid)){
ans = mid;
l = mid+1;
} else {
r = mid-1;
}
}
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
Compilation message
Main.cpp: In lambda function:
Main.cpp:40:13: warning: unused variable 'todo' [-Wunused-variable]
40 | int todo = 0, extra = 0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
3 ms |
460 KB |
Output is correct |
11 |
Correct |
175 ms |
8876 KB |
Output is correct |
12 |
Correct |
171 ms |
8816 KB |
Output is correct |
13 |
Correct |
158 ms |
8124 KB |
Output is correct |
14 |
Correct |
163 ms |
8104 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
197 ms |
8112 KB |
Output is correct |
17 |
Correct |
181 ms |
8868 KB |
Output is correct |
18 |
Correct |
171 ms |
8372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
197 ms |
8112 KB |
Output is correct |
3 |
Correct |
181 ms |
8868 KB |
Output is correct |
4 |
Correct |
171 ms |
8372 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
320 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
324 KB |
Output is correct |
13 |
Correct |
87 ms |
4596 KB |
Output is correct |
14 |
Correct |
63 ms |
3400 KB |
Output is correct |
15 |
Correct |
45 ms |
2920 KB |
Output is correct |
16 |
Correct |
37 ms |
2492 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
316 KB |
Output is correct |
22 |
Correct |
4 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
3 ms |
460 KB |
Output is correct |
11 |
Correct |
175 ms |
8876 KB |
Output is correct |
12 |
Correct |
171 ms |
8816 KB |
Output is correct |
13 |
Correct |
158 ms |
8124 KB |
Output is correct |
14 |
Correct |
163 ms |
8104 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
328 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
324 KB |
Output is correct |
23 |
Correct |
87 ms |
4596 KB |
Output is correct |
24 |
Correct |
63 ms |
3400 KB |
Output is correct |
25 |
Correct |
45 ms |
2920 KB |
Output is correct |
26 |
Correct |
37 ms |
2492 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
316 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
500 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
197 ms |
8112 KB |
Output is correct |
36 |
Correct |
181 ms |
8868 KB |
Output is correct |
37 |
Correct |
171 ms |
8372 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
4 ms |
468 KB |
Output is correct |
46 |
Correct |
6 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
33 ms |
2264 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
316 KB |
Output is correct |
51 |
Correct |
4 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
320 KB |
Output is correct |
55 |
Correct |
88 ms |
4560 KB |
Output is correct |
56 |
Correct |
55 ms |
3404 KB |
Output is correct |
57 |
Correct |
55 ms |
3436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
324 KB |
Output is correct |
9 |
Correct |
87 ms |
4596 KB |
Output is correct |
10 |
Correct |
63 ms |
3400 KB |
Output is correct |
11 |
Correct |
45 ms |
2920 KB |
Output is correct |
12 |
Correct |
37 ms |
2492 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
316 KB |
Output is correct |
18 |
Correct |
4 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
500 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
197 ms |
8112 KB |
Output is correct |
22 |
Correct |
181 ms |
8868 KB |
Output is correct |
23 |
Correct |
171 ms |
8372 KB |
Output is correct |
24 |
Correct |
36 ms |
2152 KB |
Output is correct |
25 |
Correct |
100 ms |
4216 KB |
Output is correct |
26 |
Correct |
22 ms |
1616 KB |
Output is correct |
27 |
Correct |
173 ms |
8384 KB |
Output is correct |
28 |
Correct |
185 ms |
8424 KB |
Output is correct |
29 |
Correct |
186 ms |
8344 KB |
Output is correct |
30 |
Correct |
197 ms |
8376 KB |
Output is correct |
31 |
Correct |
243 ms |
8424 KB |
Output is correct |
32 |
Correct |
219 ms |
8120 KB |
Output is correct |
33 |
Correct |
262 ms |
8888 KB |
Output is correct |
34 |
Correct |
256 ms |
8076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
3 ms |
460 KB |
Output is correct |
11 |
Correct |
175 ms |
8876 KB |
Output is correct |
12 |
Correct |
171 ms |
8816 KB |
Output is correct |
13 |
Correct |
158 ms |
8124 KB |
Output is correct |
14 |
Correct |
163 ms |
8104 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
328 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
324 KB |
Output is correct |
23 |
Correct |
87 ms |
4596 KB |
Output is correct |
24 |
Correct |
63 ms |
3400 KB |
Output is correct |
25 |
Correct |
45 ms |
2920 KB |
Output is correct |
26 |
Correct |
37 ms |
2492 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
316 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
500 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
4 ms |
468 KB |
Output is correct |
42 |
Correct |
6 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
33 ms |
2264 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
316 KB |
Output is correct |
47 |
Correct |
4 ms |
468 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
320 KB |
Output is correct |
51 |
Correct |
88 ms |
4560 KB |
Output is correct |
52 |
Correct |
55 ms |
3404 KB |
Output is correct |
53 |
Correct |
55 ms |
3436 KB |
Output is correct |
54 |
Correct |
36 ms |
2152 KB |
Output is correct |
55 |
Correct |
100 ms |
4216 KB |
Output is correct |
56 |
Correct |
22 ms |
1616 KB |
Output is correct |
57 |
Correct |
173 ms |
8384 KB |
Output is correct |
58 |
Correct |
185 ms |
8424 KB |
Output is correct |
59 |
Correct |
186 ms |
8344 KB |
Output is correct |
60 |
Correct |
197 ms |
8376 KB |
Output is correct |
61 |
Correct |
243 ms |
8424 KB |
Output is correct |
62 |
Correct |
219 ms |
8120 KB |
Output is correct |
63 |
Correct |
262 ms |
8888 KB |
Output is correct |
64 |
Correct |
256 ms |
8076 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
197 ms |
8112 KB |
Output is correct |
67 |
Correct |
181 ms |
8868 KB |
Output is correct |
68 |
Correct |
171 ms |
8372 KB |
Output is correct |
69 |
Correct |
27 ms |
1596 KB |
Output is correct |
70 |
Correct |
7 ms |
556 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
38 ms |
2088 KB |
Output is correct |
73 |
Correct |
9 ms |
716 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
188 ms |
8804 KB |
Output is correct |
76 |
Correct |
197 ms |
8740 KB |
Output is correct |
77 |
Correct |
206 ms |
8820 KB |
Output is correct |
78 |
Correct |
227 ms |
8868 KB |
Output is correct |
79 |
Correct |
261 ms |
8752 KB |
Output is correct |
80 |
Correct |
261 ms |
8780 KB |
Output is correct |
81 |
Correct |
233 ms |
8084 KB |
Output is correct |
82 |
Correct |
233 ms |
8124 KB |
Output is correct |