답안 #921494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921494 2024-02-04T02:51:47 Z cthbst Self Study (JOI22_ho_t2) C++14
100 / 100
203 ms 5384 KB
#include <algorithm>
#include <iostream>

#define int long long

using namespace std;

const int MAXN = 300005;

int n, m;
int a[MAXN];
int b[MAXN];

void init() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    for (int i = 0; i < n; i++) a[i] = max(a[i], b[i]);
}

int div_ceil(int x, int y) {
    int ans = x / y;
    if (x % y > 0) ans++;
    return ans;
}

bool check(int D) {
    //  __int128 extra = 0;
    int extra = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] * m >= D) {
            int val = m - div_ceil(D, a[i]);
            extra += val;
        } else {  // a[i] * m < D
            int val = div_ceil(D - a[i] * m, b[i]);
            extra -= val;
            if (extra < -n * m) return false;
        }
    }
    return extra >= 0;
}

void solve() {
    int l = 1;
    int r = 1 + (int)1e18;

    // check(D) : D 愈小愈容易
    while (l != r) {
        int mid = (l + r) / 2;
        if (check(mid) == false) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    int ans = r - 1;
    cout << ans << '\n';
}

signed main() {
    cin.tie(0);
    cin.sync_with_stdio(0);

    init();
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 82 ms 5064 KB Output is correct
12 Correct 82 ms 5384 KB Output is correct
13 Correct 78 ms 4956 KB Output is correct
14 Correct 58 ms 4956 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 26 ms 4956 KB Output is correct
17 Correct 87 ms 4948 KB Output is correct
18 Correct 80 ms 5272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 26 ms 4956 KB Output is correct
3 Correct 87 ms 4948 KB Output is correct
4 Correct 80 ms 5272 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 43 ms 4700 KB Output is correct
14 Correct 28 ms 4700 KB Output is correct
15 Correct 20 ms 4700 KB Output is correct
16 Correct 18 ms 4560 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2548 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 82 ms 5064 KB Output is correct
12 Correct 82 ms 5384 KB Output is correct
13 Correct 78 ms 4956 KB Output is correct
14 Correct 58 ms 4956 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 43 ms 4700 KB Output is correct
24 Correct 28 ms 4700 KB Output is correct
25 Correct 20 ms 4700 KB Output is correct
26 Correct 18 ms 4560 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2548 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 26 ms 4956 KB Output is correct
36 Correct 87 ms 4948 KB Output is correct
37 Correct 80 ms 5272 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 2 ms 2396 KB Output is correct
46 Correct 3 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 15 ms 4700 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 42 ms 4720 KB Output is correct
56 Correct 27 ms 4700 KB Output is correct
57 Correct 21 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 43 ms 4700 KB Output is correct
10 Correct 28 ms 4700 KB Output is correct
11 Correct 20 ms 4700 KB Output is correct
12 Correct 18 ms 4560 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2548 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 26 ms 4956 KB Output is correct
22 Correct 87 ms 4948 KB Output is correct
23 Correct 80 ms 5272 KB Output is correct
24 Correct 26 ms 4696 KB Output is correct
25 Correct 62 ms 4720 KB Output is correct
26 Correct 11 ms 4696 KB Output is correct
27 Correct 86 ms 5204 KB Output is correct
28 Correct 83 ms 5140 KB Output is correct
29 Correct 86 ms 5132 KB Output is correct
30 Correct 107 ms 4952 KB Output is correct
31 Correct 184 ms 5132 KB Output is correct
32 Correct 97 ms 4956 KB Output is correct
33 Correct 203 ms 4956 KB Output is correct
34 Correct 91 ms 5136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 82 ms 5064 KB Output is correct
12 Correct 82 ms 5384 KB Output is correct
13 Correct 78 ms 4956 KB Output is correct
14 Correct 58 ms 4956 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 43 ms 4700 KB Output is correct
24 Correct 28 ms 4700 KB Output is correct
25 Correct 20 ms 4700 KB Output is correct
26 Correct 18 ms 4560 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2548 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 3 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 15 ms 4700 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 42 ms 4720 KB Output is correct
52 Correct 27 ms 4700 KB Output is correct
53 Correct 21 ms 4696 KB Output is correct
54 Correct 26 ms 4696 KB Output is correct
55 Correct 62 ms 4720 KB Output is correct
56 Correct 11 ms 4696 KB Output is correct
57 Correct 86 ms 5204 KB Output is correct
58 Correct 83 ms 5140 KB Output is correct
59 Correct 86 ms 5132 KB Output is correct
60 Correct 107 ms 4952 KB Output is correct
61 Correct 184 ms 5132 KB Output is correct
62 Correct 97 ms 4956 KB Output is correct
63 Correct 203 ms 4956 KB Output is correct
64 Correct 91 ms 5136 KB Output is correct
65 Correct 1 ms 2392 KB Output is correct
66 Correct 26 ms 4956 KB Output is correct
67 Correct 87 ms 4948 KB Output is correct
68 Correct 80 ms 5272 KB Output is correct
69 Correct 21 ms 4696 KB Output is correct
70 Correct 5 ms 2396 KB Output is correct
71 Correct 1 ms 2396 KB Output is correct
72 Correct 28 ms 4752 KB Output is correct
73 Correct 6 ms 2404 KB Output is correct
74 Correct 1 ms 2396 KB Output is correct
75 Correct 87 ms 5128 KB Output is correct
76 Correct 97 ms 5132 KB Output is correct
77 Correct 106 ms 4956 KB Output is correct
78 Correct 135 ms 5204 KB Output is correct
79 Correct 198 ms 4956 KB Output is correct
80 Correct 193 ms 5320 KB Output is correct
81 Correct 195 ms 5132 KB Output is correct
82 Correct 191 ms 5132 KB Output is correct