Submission #938551

# Submission time Handle Problem Language Result Execution time Memory
938551 2024-03-05T10:04:43 Z the_coding_pooh Self Study (JOI22_ho_t2) C++14
100 / 100
236 ms 13904 KB
#include <bits/stdc++.h>
#define uwu return 0;

using namespace std;

#define fs first
#define sc second

#define int long long

using ll = long long;

const ll SIZE = 3e5 + 5;

const long long INF = 2e18 + 5;

ll N;
ll M;

ll A[SIZE], B[SIZE], rm[SIZE];

bool eval(ll mn){
    //cout << mn << '\n';
    ll left_h = 0;
    for (int i = 0; i < N;i++){
        rm[i] = mn;
        if((mn - 1LL) / A[i] + 1 < M){
            rm[i] = 0LL;
            left_h += M - ((mn - 1LL) / A[i] + 1LL);
        }
        else{
            rm[i] -= M * A[i];
        }
        //cout << rm[i] << ' ';
    }
    //cout << left_h << '\n';
    for (int i = 0; i < N;i++){
        if(rm[i] <= 0LL) continue; 
        if(left_h < (rm[i] - 1) / B[i] + 1){
            return false;
        }
        left_h -= ((rm[i] - 1LL) / B[i] + 1LL);
    }
    return true;
}

signed main(){
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> N >> M;

    for (int i = 0; i < N;i++){
        cin >> A[i];
    }

    for (int i = 0; i < N;i++){
        cin >> B[i];
        if(B[i] > A[i])
            A[i] = B[i];
    }

    ll L = 0, R = INF, m;

    while(L < R){
        m = (L + R + 1LL) >> 1;
        if(eval(m))
            L = m;
        else
            R = m - 1LL;
    }
    
    cout << L << '\n';
    uwu
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 151 ms 13204 KB Output is correct
12 Correct 163 ms 13396 KB Output is correct
13 Correct 138 ms 11092 KB Output is correct
14 Correct 137 ms 11092 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 182 ms 8656 KB Output is correct
17 Correct 149 ms 13904 KB Output is correct
18 Correct 149 ms 13276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 182 ms 8656 KB Output is correct
3 Correct 149 ms 13904 KB Output is correct
4 Correct 149 ms 13276 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 82 ms 9680 KB Output is correct
14 Correct 54 ms 8708 KB Output is correct
15 Correct 40 ms 8028 KB Output is correct
16 Correct 33 ms 7772 KB Output is correct
17 Correct 1 ms 4696 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 4 ms 4576 KB Output is correct
23 Correct 3 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 151 ms 13204 KB Output is correct
12 Correct 163 ms 13396 KB Output is correct
13 Correct 138 ms 11092 KB Output is correct
14 Correct 137 ms 11092 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 82 ms 9680 KB Output is correct
24 Correct 54 ms 8708 KB Output is correct
25 Correct 40 ms 8028 KB Output is correct
26 Correct 33 ms 7772 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 4 ms 4576 KB Output is correct
33 Correct 3 ms 4700 KB Output is correct
34 Correct 1 ms 4440 KB Output is correct
35 Correct 182 ms 8656 KB Output is correct
36 Correct 149 ms 13904 KB Output is correct
37 Correct 149 ms 13276 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 2 ms 4440 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 4 ms 4700 KB Output is correct
46 Correct 6 ms 4816 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 32 ms 7624 KB Output is correct
49 Correct 1 ms 4440 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 4 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4440 KB Output is correct
55 Correct 87 ms 9656 KB Output is correct
56 Correct 47 ms 8024 KB Output is correct
57 Correct 48 ms 7884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 82 ms 9680 KB Output is correct
10 Correct 54 ms 8708 KB Output is correct
11 Correct 40 ms 8028 KB Output is correct
12 Correct 33 ms 7772 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 4 ms 4576 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 182 ms 8656 KB Output is correct
22 Correct 149 ms 13904 KB Output is correct
23 Correct 149 ms 13276 KB Output is correct
24 Correct 34 ms 7516 KB Output is correct
25 Correct 89 ms 9372 KB Output is correct
26 Correct 20 ms 7260 KB Output is correct
27 Correct 153 ms 13272 KB Output is correct
28 Correct 165 ms 13136 KB Output is correct
29 Correct 163 ms 13140 KB Output is correct
30 Correct 185 ms 13164 KB Output is correct
31 Correct 222 ms 13276 KB Output is correct
32 Correct 205 ms 8540 KB Output is correct
33 Correct 209 ms 13756 KB Output is correct
34 Correct 229 ms 8632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 151 ms 13204 KB Output is correct
12 Correct 163 ms 13396 KB Output is correct
13 Correct 138 ms 11092 KB Output is correct
14 Correct 137 ms 11092 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 82 ms 9680 KB Output is correct
24 Correct 54 ms 8708 KB Output is correct
25 Correct 40 ms 8028 KB Output is correct
26 Correct 33 ms 7772 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 4 ms 4576 KB Output is correct
33 Correct 3 ms 4700 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 2 ms 4440 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 4 ms 4700 KB Output is correct
42 Correct 6 ms 4816 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 32 ms 7624 KB Output is correct
45 Correct 1 ms 4440 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 4 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4440 KB Output is correct
51 Correct 87 ms 9656 KB Output is correct
52 Correct 47 ms 8024 KB Output is correct
53 Correct 48 ms 7884 KB Output is correct
54 Correct 34 ms 7516 KB Output is correct
55 Correct 89 ms 9372 KB Output is correct
56 Correct 20 ms 7260 KB Output is correct
57 Correct 153 ms 13272 KB Output is correct
58 Correct 165 ms 13136 KB Output is correct
59 Correct 163 ms 13140 KB Output is correct
60 Correct 185 ms 13164 KB Output is correct
61 Correct 222 ms 13276 KB Output is correct
62 Correct 205 ms 8540 KB Output is correct
63 Correct 209 ms 13756 KB Output is correct
64 Correct 229 ms 8632 KB Output is correct
65 Correct 1 ms 4440 KB Output is correct
66 Correct 182 ms 8656 KB Output is correct
67 Correct 149 ms 13904 KB Output is correct
68 Correct 149 ms 13276 KB Output is correct
69 Correct 25 ms 7260 KB Output is correct
70 Correct 8 ms 4696 KB Output is correct
71 Correct 1 ms 4444 KB Output is correct
72 Correct 35 ms 7608 KB Output is correct
73 Correct 8 ms 4700 KB Output is correct
74 Correct 2 ms 4444 KB Output is correct
75 Correct 171 ms 13420 KB Output is correct
76 Correct 173 ms 13136 KB Output is correct
77 Correct 184 ms 13136 KB Output is correct
78 Correct 206 ms 13284 KB Output is correct
79 Correct 235 ms 13140 KB Output is correct
80 Correct 236 ms 13268 KB Output is correct
81 Correct 200 ms 11292 KB Output is correct
82 Correct 196 ms 11088 KB Output is correct