Submission #527912

# Submission time Handle Problem Language Result Execution time Memory
527912 2022-02-18T17:10:39 Z SorahISA Self Study (JOI22_ho_t2) C++17
100 / 100
432 ms 9640 KB
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define double long double
using pii = pair<int, int>;
template <typename T>
using Prior = std::priority_queue<T>;
template <typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define ee emplace
#define eb emplace_back
#define ef push_front
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

#ifdef local
#define fastIO() void()
#define debug(...) \
    cerr << "\u001b[33m" << "At func " << __FUNCTION__ << ", line " << __LINE__ << ": ",\
    cerr << "(" << #__VA_ARGS__ << ") = ",\
    _do(__VA_ARGS__),\
    cerr << "\u001b[0m"
template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif

template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}

const int INF = LLONG_MAX >> 2;

inline int divceil(int x, int y) {
    if (y < 0) x *= -1, y *= -1;
    if (x <= 0) return x / y;
    return (x - 1) / y + 1;
}

void solve() {
    int N, M; cin >> N >> M;
    
    vector<int> A(N), B(N);
    for (int &x : A) cin >> x;
    for (int &x : B) cin >> x;
    for (int i = 0; i < N; ++i) chmax(A[i], B[i]);
    
    auto calc = [&](int val) -> bool {
        __int128 give = 0, need = 0;
        for (int i = 0; i < N; ++i) {
            // debug(val, A[i], B[i], M - divceil(val, A[i]), divceil(val - A[i] * M, B[i]));
            give += max(M - divceil(val, A[i]), (int)0);
            need += max(divceil(val - A[i] * M, B[i]), (int)0);
        }
        return give >= need;
    };
    
    int lo = 0, hi = INF, mi;
    while (lo < hi) {
        mi = (lo + hi + 1) >> 1;
        if (calc(mi)) lo = mi;
        else          hi = mi - 1;
    }
    cout << lo << "\n";
}

int32_t main() {
    fastIO();
    
    int t = 1; // cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        solve();
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 312 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 4 ms 444 KB Output is correct
11 Correct 292 ms 9548 KB Output is correct
12 Correct 279 ms 9384 KB Output is correct
13 Correct 296 ms 6612 KB Output is correct
14 Correct 329 ms 8672 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 432 ms 5332 KB Output is correct
17 Correct 294 ms 5780 KB Output is correct
18 Correct 305 ms 6216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 432 ms 5332 KB Output is correct
3 Correct 294 ms 5780 KB Output is correct
4 Correct 305 ms 6216 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 135 ms 4788 KB Output is correct
14 Correct 92 ms 2700 KB Output is correct
15 Correct 65 ms 2140 KB Output is correct
16 Correct 67 ms 1852 KB Output is correct
17 Correct 2 ms 316 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 7 ms 396 KB Output is correct
23 Correct 6 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 312 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 4 ms 444 KB Output is correct
11 Correct 292 ms 9548 KB Output is correct
12 Correct 279 ms 9384 KB Output is correct
13 Correct 296 ms 6612 KB Output is correct
14 Correct 329 ms 8672 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 135 ms 4788 KB Output is correct
24 Correct 92 ms 2700 KB Output is correct
25 Correct 65 ms 2140 KB Output is correct
26 Correct 67 ms 1852 KB Output is correct
27 Correct 2 ms 316 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 7 ms 396 KB Output is correct
33 Correct 6 ms 484 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 432 ms 5332 KB Output is correct
36 Correct 294 ms 5780 KB Output is correct
37 Correct 305 ms 6216 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 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 1 ms 260 KB Output is correct
45 Correct 6 ms 436 KB Output is correct
46 Correct 11 ms 440 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 45 ms 1632 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 5 ms 332 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 133 ms 4280 KB Output is correct
56 Correct 93 ms 2384 KB Output is correct
57 Correct 120 ms 2520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 135 ms 4788 KB Output is correct
10 Correct 92 ms 2700 KB Output is correct
11 Correct 65 ms 2140 KB Output is correct
12 Correct 67 ms 1852 KB Output is correct
13 Correct 2 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 7 ms 396 KB Output is correct
19 Correct 6 ms 484 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 432 ms 5332 KB Output is correct
22 Correct 294 ms 5780 KB Output is correct
23 Correct 305 ms 6216 KB Output is correct
24 Correct 43 ms 1408 KB Output is correct
25 Correct 141 ms 3212 KB Output is correct
26 Correct 31 ms 996 KB Output is correct
27 Correct 279 ms 6704 KB Output is correct
28 Correct 306 ms 6708 KB Output is correct
29 Correct 295 ms 6704 KB Output is correct
30 Correct 265 ms 6848 KB Output is correct
31 Correct 289 ms 7988 KB Output is correct
32 Correct 408 ms 5608 KB Output is correct
33 Correct 378 ms 6652 KB Output is correct
34 Correct 409 ms 5064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 312 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 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 4 ms 444 KB Output is correct
11 Correct 292 ms 9548 KB Output is correct
12 Correct 279 ms 9384 KB Output is correct
13 Correct 296 ms 6612 KB Output is correct
14 Correct 329 ms 8672 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 292 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 135 ms 4788 KB Output is correct
24 Correct 92 ms 2700 KB Output is correct
25 Correct 65 ms 2140 KB Output is correct
26 Correct 67 ms 1852 KB Output is correct
27 Correct 2 ms 316 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 2 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 7 ms 396 KB Output is correct
33 Correct 6 ms 484 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 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 1 ms 260 KB Output is correct
41 Correct 6 ms 436 KB Output is correct
42 Correct 11 ms 440 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 45 ms 1632 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 5 ms 332 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 133 ms 4280 KB Output is correct
52 Correct 93 ms 2384 KB Output is correct
53 Correct 120 ms 2520 KB Output is correct
54 Correct 43 ms 1408 KB Output is correct
55 Correct 141 ms 3212 KB Output is correct
56 Correct 31 ms 996 KB Output is correct
57 Correct 279 ms 6704 KB Output is correct
58 Correct 306 ms 6708 KB Output is correct
59 Correct 295 ms 6704 KB Output is correct
60 Correct 265 ms 6848 KB Output is correct
61 Correct 289 ms 7988 KB Output is correct
62 Correct 408 ms 5608 KB Output is correct
63 Correct 378 ms 6652 KB Output is correct
64 Correct 409 ms 5064 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 432 ms 5332 KB Output is correct
67 Correct 294 ms 5780 KB Output is correct
68 Correct 305 ms 6216 KB Output is correct
69 Correct 30 ms 944 KB Output is correct
70 Correct 7 ms 332 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 44 ms 1144 KB Output is correct
73 Correct 12 ms 460 KB Output is correct
74 Correct 2 ms 204 KB Output is correct
75 Correct 257 ms 7024 KB Output is correct
76 Correct 260 ms 6776 KB Output is correct
77 Correct 278 ms 6156 KB Output is correct
78 Correct 265 ms 5276 KB Output is correct
79 Correct 282 ms 6744 KB Output is correct
80 Correct 269 ms 9640 KB Output is correct
81 Correct 308 ms 6520 KB Output is correct
82 Correct 367 ms 6852 KB Output is correct