#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <array>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <iomanip>
#include <cstring>
#include <string> // for getline
using namespace std;
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define e emplace
template <typename T> istream& operator>>(istream &is, vector<T>& a) { for (auto& i : a) is >> i; return is; }
template <typename T> ostream& operator<<(ostream& os, vector<T>& a) { for (auto& i : a) os << i << " "; return os; };
// template <typename T> ostream& operator<<(ostream &os, const vector<T>& v) { os << '{'; string s; for (const auto &x : v) os << s << x, s = " "; return os << '}'; }
template <typename A, typename B> istream& operator>>(istream& is, pair<A, B>& i) { return is >> i.ff >> i.ss; }
template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& i) { return os << i.ff << " " << i.ss; }
// template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& i) { return os << '{' << i.ff << ", " << i.ss << '}'; }
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using pii = pair<int, int>; using pli = pair<ll, int>; using pil = pair<int, ll>;
using pll = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>;
using vi = vector<int>; using vb = vector<bool>; using vc = vector<char>;
using vvi = vector<vi>; using vvb = vector<vb>; using vvc = vector<vc>;
using vpii = vector<pii>; using vpll = vector<pll>; using vs = vector<string>;
using tiii = tuple<int, int, int>; using vtiii = vector<tiii>;
template <class A, class B> using umap = unordered_map<A, B>;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bug cerr << "!Bugged..." << endl
#define add(x, y) (x + y >= MOD ? x + y - MOD : x + y)
const vs cq = { "NO", "YES"};
const int dx[8] = { -1, 0, 0, 1, 1, 1, -1, -1};
const int dy[8] = { 0, -1, 1, 0, 1, -1, 1, -1};
const int INF = 2147483647;
const ll LINF = 9223372036854775807;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 1;
int main()
{
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("error.txt", "a", stderr);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// cout.tie(NULL);
int ttt(1);
// cin >> ttt;
for (int itt = 1; itt <= ttt; itt++)
{
ll n, m;
cin >> n >> m;
vl a(n); cin >> a;
vl b(n); cin >> b;
vl c(n);
for (int i = 0; i < n; i++) {
c[i] = max(a[i], b[i]);
}
ll l = 0, r = 1e18, ans;
auto chk = [&](ll x) {
ll days = n * m;
vl cur(n, x); // c[i] * g >= x;
for (int i = 0; i < n; ++i) {
if (a[i] <= b[i]) continue;
ll g = (x + c[i] - 1) / c[i];
g = min(g, m);
cur[i] -= c[i] * g;
days -= g;
if (days < 0) return false;
}
for (int i = 0; i < n; ++i) {
if (cur[i] > 0) {
ll g = (cur[i] + b[i] - 1) / b[i];
days -= g;
}
if (days < 0) return false;
}
// debug(x, days);
// debug(cur);
return true;
};
while (l <= r) {
ll mid = (l + r) >> 1;
if (chk(mid)) l = mid + 1, ans = mid;
else r = mid - 1;
}
cout << ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
201 ms |
9836 KB |
Output is correct |
12 |
Correct |
205 ms |
9832 KB |
Output is correct |
13 |
Correct |
149 ms |
9832 KB |
Output is correct |
14 |
Correct |
167 ms |
9840 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
62 ms |
9840 KB |
Output is correct |
17 |
Correct |
127 ms |
9832 KB |
Output is correct |
18 |
Correct |
135 ms |
9916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
62 ms |
9840 KB |
Output is correct |
3 |
Correct |
127 ms |
9832 KB |
Output is correct |
4 |
Correct |
135 ms |
9916 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 |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
320 KB |
Output is correct |
13 |
Correct |
59 ms |
5084 KB |
Output is correct |
14 |
Correct |
43 ms |
3556 KB |
Output is correct |
15 |
Correct |
33 ms |
2780 KB |
Output is correct |
16 |
Correct |
29 ms |
2328 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
320 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
201 ms |
9836 KB |
Output is correct |
12 |
Correct |
205 ms |
9832 KB |
Output is correct |
13 |
Correct |
149 ms |
9832 KB |
Output is correct |
14 |
Correct |
167 ms |
9840 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
19 |
Correct |
0 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 |
0 ms |
320 KB |
Output is correct |
23 |
Correct |
59 ms |
5084 KB |
Output is correct |
24 |
Correct |
43 ms |
3556 KB |
Output is correct |
25 |
Correct |
33 ms |
2780 KB |
Output is correct |
26 |
Correct |
29 ms |
2328 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
320 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
62 ms |
9840 KB |
Output is correct |
36 |
Correct |
127 ms |
9832 KB |
Output is correct |
37 |
Correct |
135 ms |
9916 KB |
Output is correct |
38 |
Correct |
1 ms |
320 KB |
Output is correct |
39 |
Correct |
1 ms |
316 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
316 KB |
Output is correct |
43 |
Correct |
1 ms |
320 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
5 ms |
460 KB |
Output is correct |
46 |
Correct |
6 ms |
724 KB |
Output is correct |
47 |
Correct |
2 ms |
340 KB |
Output is correct |
48 |
Correct |
35 ms |
2036 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
3 ms |
540 KB |
Output is correct |
52 |
Correct |
1 ms |
324 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
97 ms |
5052 KB |
Output is correct |
56 |
Correct |
47 ms |
3584 KB |
Output is correct |
57 |
Correct |
62 ms |
3540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
59 ms |
5084 KB |
Output is correct |
10 |
Correct |
43 ms |
3556 KB |
Output is correct |
11 |
Correct |
33 ms |
2780 KB |
Output is correct |
12 |
Correct |
29 ms |
2328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
320 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
62 ms |
9840 KB |
Output is correct |
22 |
Correct |
127 ms |
9832 KB |
Output is correct |
23 |
Correct |
135 ms |
9916 KB |
Output is correct |
24 |
Correct |
36 ms |
1940 KB |
Output is correct |
25 |
Correct |
82 ms |
4604 KB |
Output is correct |
26 |
Correct |
20 ms |
1360 KB |
Output is correct |
27 |
Correct |
129 ms |
9832 KB |
Output is correct |
28 |
Correct |
132 ms |
9796 KB |
Output is correct |
29 |
Correct |
127 ms |
9804 KB |
Output is correct |
30 |
Correct |
150 ms |
9824 KB |
Output is correct |
31 |
Correct |
235 ms |
9804 KB |
Output is correct |
32 |
Correct |
149 ms |
10880 KB |
Output is correct |
33 |
Correct |
303 ms |
16172 KB |
Output is correct |
34 |
Correct |
151 ms |
10876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
201 ms |
9836 KB |
Output is correct |
12 |
Correct |
205 ms |
9832 KB |
Output is correct |
13 |
Correct |
149 ms |
9832 KB |
Output is correct |
14 |
Correct |
167 ms |
9840 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
19 |
Correct |
0 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 |
0 ms |
320 KB |
Output is correct |
23 |
Correct |
59 ms |
5084 KB |
Output is correct |
24 |
Correct |
43 ms |
3556 KB |
Output is correct |
25 |
Correct |
33 ms |
2780 KB |
Output is correct |
26 |
Correct |
29 ms |
2328 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
320 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
316 KB |
Output is correct |
39 |
Correct |
1 ms |
320 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
5 ms |
460 KB |
Output is correct |
42 |
Correct |
6 ms |
724 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
35 ms |
2036 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
3 ms |
540 KB |
Output is correct |
48 |
Correct |
1 ms |
324 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
97 ms |
5052 KB |
Output is correct |
52 |
Correct |
47 ms |
3584 KB |
Output is correct |
53 |
Correct |
62 ms |
3540 KB |
Output is correct |
54 |
Correct |
36 ms |
1940 KB |
Output is correct |
55 |
Correct |
82 ms |
4604 KB |
Output is correct |
56 |
Correct |
20 ms |
1360 KB |
Output is correct |
57 |
Correct |
129 ms |
9832 KB |
Output is correct |
58 |
Correct |
132 ms |
9796 KB |
Output is correct |
59 |
Correct |
127 ms |
9804 KB |
Output is correct |
60 |
Correct |
150 ms |
9824 KB |
Output is correct |
61 |
Correct |
235 ms |
9804 KB |
Output is correct |
62 |
Correct |
149 ms |
10880 KB |
Output is correct |
63 |
Correct |
303 ms |
16172 KB |
Output is correct |
64 |
Correct |
151 ms |
10876 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
62 ms |
9840 KB |
Output is correct |
67 |
Correct |
127 ms |
9832 KB |
Output is correct |
68 |
Correct |
135 ms |
9916 KB |
Output is correct |
69 |
Correct |
32 ms |
1864 KB |
Output is correct |
70 |
Correct |
8 ms |
592 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
41 ms |
2512 KB |
Output is correct |
73 |
Correct |
9 ms |
888 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
240 ms |
15604 KB |
Output is correct |
76 |
Correct |
222 ms |
15580 KB |
Output is correct |
77 |
Correct |
234 ms |
15504 KB |
Output is correct |
78 |
Correct |
254 ms |
15596 KB |
Output is correct |
79 |
Correct |
257 ms |
15504 KB |
Output is correct |
80 |
Correct |
291 ms |
15520 KB |
Output is correct |
81 |
Correct |
255 ms |
13632 KB |
Output is correct |
82 |
Correct |
262 ms |
13500 KB |
Output is correct |