Submission #1041248

# Submission time Handle Problem Language Result Execution time Memory
1041248 2024-08-01T19:45:08 Z SoulKnight Self Study (JOI22_ho_t2) C++17
100 / 100
117 ms 11344 KB
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ln '\n'

const int N = 3e5 + 5;
const ll INF = 1e18 + 5;

ll n, m, a[N], b[N];
inline ll ceil(ll x, ll y) {return (x + y - 1) / y;}

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

    // ll l = 25, r = 25, ans = 0;
    ll l = 0, r = INF, ans = 0;
    while (l <= r){
        ll tar = (l + r) / 2;
        uint64_t free, need; free = need = 0;

        for (int i = 0; i < n; i++){
            if (b[i] >= a[i]) {
                free += max(0LL, m - ceil(tar, b[i]));
                need += max(0LL, ceil(tar, b[i]) - m);
            } else {
                ll go_lesson = min(m, ceil(tar, a[i]));
                need += max(0LL, ceil(tar - a[i] * go_lesson, b[i]));
                free += max(0LL, m - go_lesson);
            }
            // cout << need << ' ' << free << ln;
        }
        if (need <= free) {ans = tar; l = tar + 1;}
        else r = tar - 1;
    }
    cout << ans << ln;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // int TT; cin >> TT;
    // while (TT--) {solve();}

    solve();

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 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 2 ms 2396 KB Output is correct
11 Correct 117 ms 10924 KB Output is correct
12 Correct 107 ms 10796 KB Output is correct
13 Correct 62 ms 8916 KB Output is correct
14 Correct 100 ms 8940 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 61 ms 6304 KB Output is correct
17 Correct 74 ms 11344 KB Output is correct
18 Correct 70 ms 10832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 61 ms 6304 KB Output is correct
3 Correct 74 ms 11344 KB Output is correct
4 Correct 70 ms 10832 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 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 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 34 ms 7648 KB Output is correct
14 Correct 27 ms 5020 KB Output is correct
15 Correct 17 ms 4440 KB Output is correct
16 Correct 14 ms 5720 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 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 2 ms 2396 KB Output is correct
11 Correct 117 ms 10924 KB Output is correct
12 Correct 107 ms 10796 KB Output is correct
13 Correct 62 ms 8916 KB Output is correct
14 Correct 100 ms 8940 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 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 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 34 ms 7648 KB Output is correct
24 Correct 27 ms 5020 KB Output is correct
25 Correct 17 ms 4440 KB Output is correct
26 Correct 14 ms 5720 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2648 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 61 ms 6304 KB Output is correct
36 Correct 74 ms 11344 KB Output is correct
37 Correct 70 ms 10832 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 0 ms 2396 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 3 ms 2652 KB Output is correct
47 Correct 1 ms 2392 KB Output is correct
48 Correct 17 ms 3904 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 2 ms 2640 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 52 ms 6492 KB Output is correct
56 Correct 20 ms 5980 KB Output is correct
57 Correct 33 ms 4424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 34 ms 7648 KB Output is correct
10 Correct 27 ms 5020 KB Output is correct
11 Correct 17 ms 4440 KB Output is correct
12 Correct 14 ms 5720 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2648 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 61 ms 6304 KB Output is correct
22 Correct 74 ms 11344 KB Output is correct
23 Correct 70 ms 10832 KB Output is correct
24 Correct 13 ms 3676 KB Output is correct
25 Correct 39 ms 6140 KB Output is correct
26 Correct 10 ms 3420 KB Output is correct
27 Correct 71 ms 10756 KB Output is correct
28 Correct 70 ms 10760 KB Output is correct
29 Correct 72 ms 10848 KB Output is correct
30 Correct 75 ms 10792 KB Output is correct
31 Correct 69 ms 10832 KB Output is correct
32 Correct 55 ms 6240 KB Output is correct
33 Correct 73 ms 11344 KB Output is correct
34 Correct 61 ms 6300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 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 2 ms 2396 KB Output is correct
11 Correct 117 ms 10924 KB Output is correct
12 Correct 107 ms 10796 KB Output is correct
13 Correct 62 ms 8916 KB Output is correct
14 Correct 100 ms 8940 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 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 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 34 ms 7648 KB Output is correct
24 Correct 27 ms 5020 KB Output is correct
25 Correct 17 ms 4440 KB Output is correct
26 Correct 14 ms 5720 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2648 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 3 ms 2652 KB Output is correct
43 Correct 1 ms 2392 KB Output is correct
44 Correct 17 ms 3904 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 2 ms 2640 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 52 ms 6492 KB Output is correct
52 Correct 20 ms 5980 KB Output is correct
53 Correct 33 ms 4424 KB Output is correct
54 Correct 13 ms 3676 KB Output is correct
55 Correct 39 ms 6140 KB Output is correct
56 Correct 10 ms 3420 KB Output is correct
57 Correct 71 ms 10756 KB Output is correct
58 Correct 70 ms 10760 KB Output is correct
59 Correct 72 ms 10848 KB Output is correct
60 Correct 75 ms 10792 KB Output is correct
61 Correct 69 ms 10832 KB Output is correct
62 Correct 55 ms 6240 KB Output is correct
63 Correct 73 ms 11344 KB Output is correct
64 Correct 61 ms 6300 KB Output is correct
65 Correct 0 ms 2396 KB Output is correct
66 Correct 61 ms 6304 KB Output is correct
67 Correct 74 ms 11344 KB Output is correct
68 Correct 70 ms 10832 KB Output is correct
69 Correct 13 ms 3164 KB Output is correct
70 Correct 3 ms 2652 KB Output is correct
71 Correct 0 ms 2396 KB Output is correct
72 Correct 14 ms 5572 KB Output is correct
73 Correct 3 ms 2652 KB Output is correct
74 Correct 1 ms 2396 KB Output is correct
75 Correct 117 ms 10884 KB Output is correct
76 Correct 112 ms 10768 KB Output is correct
77 Correct 108 ms 10940 KB Output is correct
78 Correct 107 ms 10944 KB Output is correct
79 Correct 106 ms 10912 KB Output is correct
80 Correct 111 ms 10940 KB Output is correct
81 Correct 62 ms 8788 KB Output is correct
82 Correct 99 ms 8896 KB Output is correct