답안 #624570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624570 2022-08-08T13:30:26 Z dooompy Self Study (JOI22_ho_t2) C++17
100 / 100
245 ms 11444 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

ll n, m;

ll a[300005], b[300005];

bool able(ll target) {

    ll debt = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] * m >= target) {
            debt -= m - (target + a[i] - 1) / a[i];
        }  else {
            debt += (target - a[i] * m + b[i] - 1) / b[i];
        }

        if (debt > n*m) return false;
    }


    return (debt <= 0);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    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]);

    ll l = 0, r = 1e18;
    ll ans = 0;

//    cout << able(12) << endl;


    while (l <= r) {
        ll mid = (l + r) / 2;

//        cout << l << " " << r << " " << mid << endl;

        if (able(mid)) {
            ans = mid;
            l = mid + 1;
        } else r = mid - 1;
    }

    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 109 ms 10740 KB Output is correct
12 Correct 97 ms 10792 KB Output is correct
13 Correct 95 ms 8792 KB Output is correct
14 Correct 76 ms 8712 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 34 ms 6168 KB Output is correct
17 Correct 138 ms 11444 KB Output is correct
18 Correct 101 ms 10704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 34 ms 6168 KB Output is correct
3 Correct 138 ms 11444 KB Output is correct
4 Correct 101 ms 10704 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 53 ms 5448 KB Output is correct
14 Correct 35 ms 3736 KB Output is correct
15 Correct 24 ms 2916 KB Output is correct
16 Correct 21 ms 2324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 109 ms 10740 KB Output is correct
12 Correct 97 ms 10792 KB Output is correct
13 Correct 95 ms 8792 KB Output is correct
14 Correct 76 ms 8712 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 328 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 53 ms 5448 KB Output is correct
24 Correct 35 ms 3736 KB Output is correct
25 Correct 24 ms 2916 KB Output is correct
26 Correct 21 ms 2324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 3 ms 468 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 34 ms 6168 KB Output is correct
36 Correct 138 ms 11444 KB Output is correct
37 Correct 101 ms 10704 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 3 ms 468 KB Output is correct
46 Correct 5 ms 584 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 19 ms 2112 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 0 ms 328 KB Output is correct
53 Correct 1 ms 240 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 50 ms 5452 KB Output is correct
56 Correct 34 ms 3156 KB Output is correct
57 Correct 29 ms 3120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 53 ms 5448 KB Output is correct
10 Correct 35 ms 3736 KB Output is correct
11 Correct 24 ms 2916 KB Output is correct
12 Correct 21 ms 2324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 34 ms 6168 KB Output is correct
22 Correct 138 ms 11444 KB Output is correct
23 Correct 101 ms 10704 KB Output is correct
24 Correct 29 ms 1928 KB Output is correct
25 Correct 73 ms 4940 KB Output is correct
26 Correct 14 ms 1412 KB Output is correct
27 Correct 96 ms 10764 KB Output is correct
28 Correct 112 ms 10824 KB Output is correct
29 Correct 107 ms 10736 KB Output is correct
30 Correct 130 ms 10724 KB Output is correct
31 Correct 205 ms 10796 KB Output is correct
32 Correct 111 ms 6144 KB Output is correct
33 Correct 244 ms 11364 KB Output is correct
34 Correct 109 ms 6172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 109 ms 10740 KB Output is correct
12 Correct 97 ms 10792 KB Output is correct
13 Correct 95 ms 8792 KB Output is correct
14 Correct 76 ms 8712 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 328 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 53 ms 5448 KB Output is correct
24 Correct 35 ms 3736 KB Output is correct
25 Correct 24 ms 2916 KB Output is correct
26 Correct 21 ms 2324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 3 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 5 ms 584 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 19 ms 2112 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 0 ms 328 KB Output is correct
49 Correct 1 ms 240 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 50 ms 5452 KB Output is correct
52 Correct 34 ms 3156 KB Output is correct
53 Correct 29 ms 3120 KB Output is correct
54 Correct 29 ms 1928 KB Output is correct
55 Correct 73 ms 4940 KB Output is correct
56 Correct 14 ms 1412 KB Output is correct
57 Correct 96 ms 10764 KB Output is correct
58 Correct 112 ms 10824 KB Output is correct
59 Correct 107 ms 10736 KB Output is correct
60 Correct 130 ms 10724 KB Output is correct
61 Correct 205 ms 10796 KB Output is correct
62 Correct 111 ms 6144 KB Output is correct
63 Correct 244 ms 11364 KB Output is correct
64 Correct 109 ms 6172 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 34 ms 6168 KB Output is correct
67 Correct 138 ms 11444 KB Output is correct
68 Correct 101 ms 10704 KB Output is correct
69 Correct 23 ms 1468 KB Output is correct
70 Correct 6 ms 600 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 32 ms 1736 KB Output is correct
73 Correct 7 ms 596 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 109 ms 10728 KB Output is correct
76 Correct 116 ms 10892 KB Output is correct
77 Correct 131 ms 10792 KB Output is correct
78 Correct 160 ms 10808 KB Output is correct
79 Correct 207 ms 10796 KB Output is correct
80 Correct 221 ms 10796 KB Output is correct
81 Correct 233 ms 8784 KB Output is correct
82 Correct 245 ms 8812 KB Output is correct