Submission #526483

# Submission time Handle Problem Language Result Execution time Memory
526483 2022-02-15T01:29:41 Z PurpleCrayon Self Study (JOI22_ho_t2) C++17
100 / 100
367 ms 9680 KB
#include <bits/stdc++.h>
using namespace std;
 
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int MAXN = 2e5+10, MOD = 1e9+7;
const ll INF = (long long)1e18+10;

void solve() {
    // a[i] := max(a[i], b[i])
    // binary search, take the minimum number of a's such that I'm satisfied

    int n; ll m; cin >> n >> m;
    vector<ll> a(n), b(n);
    for (auto& x : a) cin >> x;
    for (auto& x : b) cin >> x;
    for (int i = 0; i < n; i++) a[i] = max(a[i], b[i]);

    auto v = [&](ll x) -> bool {
        __int128 has = 0;
        for (int i = 0; i < n; i++) {
            ll need = (x + a[i] - 1) / a[i];
            if (need <= m) has += m - need;
            else has -= (x - a[i] * m + b[i] - 1) / b[i];
        }
        return has >= 0;
    };

    ll lo = 0, hi = INF, mid = (lo + hi) / 2;
    while (lo < mid && mid < hi) {
        if (v(mid)) lo = mid;
        else hi = mid;
        mid = (lo + hi) / 2;
    }
    cout << lo << '\n';
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int T=1;
    // cin >> T;
    while (T--) solve();
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 236 ms 4996 KB Output is correct
12 Correct 224 ms 4940 KB Output is correct
13 Correct 233 ms 4940 KB Output is correct
14 Correct 281 ms 5008 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 362 ms 5324 KB Output is correct
17 Correct 255 ms 5772 KB Output is correct
18 Correct 236 ms 6212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 362 ms 5324 KB Output is correct
3 Correct 255 ms 5772 KB Output is correct
4 Correct 236 ms 6212 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 115 ms 2652 KB Output is correct
14 Correct 76 ms 1884 KB Output is correct
15 Correct 58 ms 1484 KB Output is correct
16 Correct 46 ms 1228 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 6 ms 332 KB Output is correct
23 Correct 5 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 236 ms 4996 KB Output is correct
12 Correct 224 ms 4940 KB Output is correct
13 Correct 233 ms 4940 KB Output is correct
14 Correct 281 ms 5008 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 115 ms 2652 KB Output is correct
24 Correct 76 ms 1884 KB Output is correct
25 Correct 58 ms 1484 KB Output is correct
26 Correct 46 ms 1228 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 5 ms 404 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 362 ms 5324 KB Output is correct
36 Correct 255 ms 5772 KB Output is correct
37 Correct 236 ms 6212 KB Output is correct
38 Correct 0 ms 208 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 5 ms 412 KB Output is correct
46 Correct 8 ms 556 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 41 ms 1700 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 4 ms 400 KB Output is correct
52 Correct 0 ms 204 KB Output is correct
53 Correct 0 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 117 ms 4328 KB Output is correct
56 Correct 81 ms 2372 KB Output is correct
57 Correct 102 ms 2444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 115 ms 2652 KB Output is correct
10 Correct 76 ms 1884 KB Output is correct
11 Correct 58 ms 1484 KB Output is correct
12 Correct 46 ms 1228 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 6 ms 332 KB Output is correct
19 Correct 5 ms 404 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 362 ms 5324 KB Output is correct
22 Correct 255 ms 5772 KB Output is correct
23 Correct 236 ms 6212 KB Output is correct
24 Correct 39 ms 1312 KB Output is correct
25 Correct 112 ms 3192 KB Output is correct
26 Correct 25 ms 884 KB Output is correct
27 Correct 230 ms 6752 KB Output is correct
28 Correct 246 ms 6736 KB Output is correct
29 Correct 235 ms 6732 KB Output is correct
30 Correct 245 ms 6844 KB Output is correct
31 Correct 233 ms 8152 KB Output is correct
32 Correct 342 ms 5604 KB Output is correct
33 Correct 244 ms 6644 KB Output is correct
34 Correct 367 ms 5060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 236 ms 4996 KB Output is correct
12 Correct 224 ms 4940 KB Output is correct
13 Correct 233 ms 4940 KB Output is correct
14 Correct 281 ms 5008 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 115 ms 2652 KB Output is correct
24 Correct 76 ms 1884 KB Output is correct
25 Correct 58 ms 1484 KB Output is correct
26 Correct 46 ms 1228 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 5 ms 404 KB Output is correct
34 Correct 0 ms 208 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 5 ms 412 KB Output is correct
42 Correct 8 ms 556 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 41 ms 1700 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 4 ms 400 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 117 ms 4328 KB Output is correct
52 Correct 81 ms 2372 KB Output is correct
53 Correct 102 ms 2444 KB Output is correct
54 Correct 39 ms 1312 KB Output is correct
55 Correct 112 ms 3192 KB Output is correct
56 Correct 25 ms 884 KB Output is correct
57 Correct 230 ms 6752 KB Output is correct
58 Correct 246 ms 6736 KB Output is correct
59 Correct 235 ms 6732 KB Output is correct
60 Correct 245 ms 6844 KB Output is correct
61 Correct 233 ms 8152 KB Output is correct
62 Correct 342 ms 5604 KB Output is correct
63 Correct 244 ms 6644 KB Output is correct
64 Correct 367 ms 5060 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 362 ms 5324 KB Output is correct
67 Correct 255 ms 5772 KB Output is correct
68 Correct 236 ms 6212 KB Output is correct
69 Correct 28 ms 972 KB Output is correct
70 Correct 7 ms 436 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 39 ms 1140 KB Output is correct
73 Correct 9 ms 596 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 232 ms 7020 KB Output is correct
76 Correct 233 ms 6836 KB Output is correct
77 Correct 244 ms 6244 KB Output is correct
78 Correct 243 ms 5148 KB Output is correct
79 Correct 255 ms 6756 KB Output is correct
80 Correct 246 ms 9680 KB Output is correct
81 Correct 225 ms 6620 KB Output is correct
82 Correct 221 ms 6856 KB Output is correct