#pragma GCC optimize "trapv"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
#define vi vector<ll>
#define vb vector<bool>
#define f0(i,a) for(ll i=0;i<(a);i++)
#define f1(i,a) for(ll i=1;i<(a);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define f first
#define s second
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
Fun fun_;
public:
template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
#ifdef I_AM_NOOB
#define gg(...) [](const auto&...x){ char c='='; cerr<<#__VA_ARGS__; ((cerr<<exchange(c,',')<<x),...); cerr<<endl; }(__VA_ARGS__);
#else
#define gg(...) 777771449
#endif
ll LOG2(ll x){ return __builtin_clzll(1ll) - __builtin_clzll(x); }
bool isPow2(ll n) {
return n && ((n & (n-1)) == 0);
}
ll LOG2C(ll x) {
if (isPow2(x)) return LOG2(x);
return LOG2(x)+1;
}
template <typename Iter, typename Cont>
bool is_last(Iter iter, const Cont& cont) {
return (iter != cont.end()) && (next(iter) == cont.end());
}
constexpr ll INFF = 1e18;
constexpr ll P = 1e9+7;
// constexpr ll P = 998244353;
int main() {
cin.tie(0) -> ios::sync_with_stdio(0);
ll n, m; while (cin >> n >> m) {
vi a(n), b(n);
for (auto&x:a) cin >> x;
for (auto&x:b) cin >> x;
// f0(i, n) if (a[i] < b[i]) a[i] = b[i];
auto check = [&](ll x) -> bool {
ll days = n*m;
f0(i, n) {
ll c = x;
if (a[i] > b[i]) {
ll d = min(m, (x + a[i]-1) / a[i]);
days -= d;
c -= a[i] * d;
}
if (c > 0) days -= (c + b[i] - 1) / b[i];
if (days < 0) return false;
}
return true;
};
ll K = 0, D = 1e18;
while (D) {
while (check(K+D)) K += D;
D /= 2;
}
cout << K << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
199 ms |
5016 KB |
Output is correct |
12 |
Correct |
195 ms |
5008 KB |
Output is correct |
13 |
Correct |
94 ms |
4948 KB |
Output is correct |
14 |
Correct |
79 ms |
5012 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
36 ms |
6160 KB |
Output is correct |
17 |
Correct |
106 ms |
11400 KB |
Output is correct |
18 |
Correct |
113 ms |
10760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
36 ms |
6160 KB |
Output is correct |
3 |
Correct |
106 ms |
11400 KB |
Output is correct |
4 |
Correct |
113 ms |
10760 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
260 KB |
Output is correct |
7 |
Correct |
0 ms |
212 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 |
288 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
65 ms |
2664 KB |
Output is correct |
14 |
Correct |
42 ms |
1876 KB |
Output is correct |
15 |
Correct |
33 ms |
1492 KB |
Output is correct |
16 |
Correct |
32 ms |
1236 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
199 ms |
5016 KB |
Output is correct |
12 |
Correct |
195 ms |
5008 KB |
Output is correct |
13 |
Correct |
94 ms |
4948 KB |
Output is correct |
14 |
Correct |
79 ms |
5012 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
260 KB |
Output is correct |
17 |
Correct |
0 ms |
212 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 |
288 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
65 ms |
2664 KB |
Output is correct |
24 |
Correct |
42 ms |
1876 KB |
Output is correct |
25 |
Correct |
33 ms |
1492 KB |
Output is correct |
26 |
Correct |
32 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
36 ms |
6160 KB |
Output is correct |
36 |
Correct |
106 ms |
11400 KB |
Output is correct |
37 |
Correct |
113 ms |
10760 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
5 ms |
468 KB |
Output is correct |
46 |
Correct |
7 ms |
636 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
45 ms |
2132 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
5 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
104 ms |
5520 KB |
Output is correct |
56 |
Correct |
40 ms |
3156 KB |
Output is correct |
57 |
Correct |
32 ms |
3156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
0 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 |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
65 ms |
2664 KB |
Output is correct |
10 |
Correct |
42 ms |
1876 KB |
Output is correct |
11 |
Correct |
33 ms |
1492 KB |
Output is correct |
12 |
Correct |
32 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
336 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
36 ms |
6160 KB |
Output is correct |
22 |
Correct |
106 ms |
11400 KB |
Output is correct |
23 |
Correct |
113 ms |
10760 KB |
Output is correct |
24 |
Correct |
35 ms |
1876 KB |
Output is correct |
25 |
Correct |
82 ms |
4944 KB |
Output is correct |
26 |
Correct |
16 ms |
1364 KB |
Output is correct |
27 |
Correct |
115 ms |
10812 KB |
Output is correct |
28 |
Correct |
130 ms |
10820 KB |
Output is correct |
29 |
Correct |
141 ms |
10796 KB |
Output is correct |
30 |
Correct |
156 ms |
10820 KB |
Output is correct |
31 |
Correct |
250 ms |
10700 KB |
Output is correct |
32 |
Correct |
138 ms |
6188 KB |
Output is correct |
33 |
Correct |
208 ms |
11468 KB |
Output is correct |
34 |
Correct |
142 ms |
6184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
340 KB |
Output is correct |
11 |
Correct |
199 ms |
5016 KB |
Output is correct |
12 |
Correct |
195 ms |
5008 KB |
Output is correct |
13 |
Correct |
94 ms |
4948 KB |
Output is correct |
14 |
Correct |
79 ms |
5012 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
260 KB |
Output is correct |
17 |
Correct |
0 ms |
212 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 |
288 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
65 ms |
2664 KB |
Output is correct |
24 |
Correct |
42 ms |
1876 KB |
Output is correct |
25 |
Correct |
33 ms |
1492 KB |
Output is correct |
26 |
Correct |
32 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
5 ms |
468 KB |
Output is correct |
42 |
Correct |
7 ms |
636 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
45 ms |
2132 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
5 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
104 ms |
5520 KB |
Output is correct |
52 |
Correct |
40 ms |
3156 KB |
Output is correct |
53 |
Correct |
32 ms |
3156 KB |
Output is correct |
54 |
Correct |
35 ms |
1876 KB |
Output is correct |
55 |
Correct |
82 ms |
4944 KB |
Output is correct |
56 |
Correct |
16 ms |
1364 KB |
Output is correct |
57 |
Correct |
115 ms |
10812 KB |
Output is correct |
58 |
Correct |
130 ms |
10820 KB |
Output is correct |
59 |
Correct |
141 ms |
10796 KB |
Output is correct |
60 |
Correct |
156 ms |
10820 KB |
Output is correct |
61 |
Correct |
250 ms |
10700 KB |
Output is correct |
62 |
Correct |
138 ms |
6188 KB |
Output is correct |
63 |
Correct |
208 ms |
11468 KB |
Output is correct |
64 |
Correct |
142 ms |
6184 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
36 ms |
6160 KB |
Output is correct |
67 |
Correct |
106 ms |
11400 KB |
Output is correct |
68 |
Correct |
113 ms |
10760 KB |
Output is correct |
69 |
Correct |
40 ms |
1364 KB |
Output is correct |
70 |
Correct |
10 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
55 ms |
1748 KB |
Output is correct |
73 |
Correct |
12 ms |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
217 ms |
10820 KB |
Output is correct |
76 |
Correct |
270 ms |
10828 KB |
Output is correct |
77 |
Correct |
288 ms |
10820 KB |
Output is correct |
78 |
Correct |
326 ms |
10828 KB |
Output is correct |
79 |
Correct |
405 ms |
10760 KB |
Output is correct |
80 |
Correct |
378 ms |
10700 KB |
Output is correct |
81 |
Correct |
196 ms |
8828 KB |
Output is correct |
82 |
Correct |
180 ms |
8836 KB |
Output is correct |