답안 #750690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750690 2023-05-30T07:08:58 Z Kihihihi Self Study (JOI22_ho_t2) C++17
62 / 100
232 ms 11524 KB
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <ctime>
#include <chrono>
#include <cstdio>
#include <random>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <bitset>
#include <list>
#include <fstream>
#include <functional>
#include <complex>
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

short skip_cin = 0;
const long long INF = 1e18, MOD = 1e9 + 7, MOD2 = 998244353, LOG = 19;
const long double EPS = 1e-9, PI = acos(-1);

bool check(long long n, long long m, vector<long long>& a, vector<long long>& b, long long nd)
{
    long long bal = 0;
    for (long long i = 0; i < n; i++)
    {
        if (a[i] * m <= nd)
        {
            long long add = ((nd - a[i] * m) + b[i] - 1) / b[i];
            if (add > n * m)
            {
                return false;
            }
            bal -= add;
        }
        else
        {
            long long del = (a[i] * m - nd) / a[i];
            del = min(del, m);
            bal += del;
        }
        if (bal < -n * m)
        {
            return false;
        }
    }
    return bal >= 0;
}

void solve()
{
    long long n, m;
    vector<long long> a, b;
    cin >> n >> m;
    a.resize(n);
    b.resize(n);
    for (long long i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (long long i = 0; i < n; i++)
    {
        cin >> b[i];
        a[i] = max(a[i], b[i]);
    }

    long long left = 0, right = 1e18 + 5;
    while (right - left > 1)
    {
        long long mid = (left + right) / 2;
        if (check(n, m, a, b, mid))
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }
    cout << left << "\n";
}

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

    int tst = 1;
    //cin >> tst;
    while (tst--)
    {
        solve();
    }

    return 0;
}

/*
<3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠤⠖⠚⢉⣩⣭⡭⠛⠓⠲⠦⣄⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢀⡴⠋⠁⠀⠀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠳⢦⡀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡴⠃⢀⡴⢳⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣆⠀⠀⠀
⠀⠀⠀⠀⡾⠁⣠⠋⠀⠈⢧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢧⠀⠀
⠀⠀⠀⣸⠁⢰⠃⠀⠀⠀⠈⢣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣇⠀
⠀⠀⠀⡇⠀⡾⡀⠀⠀⠀⠀⣀⣹⣆⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⠀
⠀⠀⢸⠃⢀⣇⡈⠀⠀⠀⠀⠀⠀⢀⡑⢄⡀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇
⠀⠀⢸⠀⢻⡟⡻⢶⡆⠀⠀⠀⠀⡼⠟⡳⢿⣦⡑⢄⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇
⠀⠀⣸⠀⢸⠃⡇⢀⠇⠀⠀⠀⠀⠀⡼⠀⠀⠈⣿⡗⠂⠀⠀⠀⠀⠀⠀⠀⢸⠁
⠀⠀⡏⠀⣼⠀⢳⠊⠀⠀⠀⠀⠀⠀⠱⣀⣀⠔⣸⠁⠀⠀⠀⠀⠀⠀⠀⢠⡟⠀
⠀⠀⡇⢀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⢸⠃⠀
⠀⢸⠃⠘⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠁⠀⠀⢀⠀⠀⠀⠀⠀⣾⠀⠀
⠀⣸⠀⠀⠹⡄⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⡞⠀⠀⠀⠸⠀⠀⠀⠀⠀⡇⠀⠀
⠀⡏⠀⠀⠀⠙⣆⠀⠀⠀⠀⠀⠀⠀⢀⣠⢶⡇⠀⠀⢰⡀⠀⠀⠀⠀⠀⡇⠀⠀
⢰⠇⡄⠀⠀⠀⡿⢣⣀⣀⣀⡤⠴⡞⠉⠀⢸⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⣧⠀⠀
⣸⠀⡇⠀⠀⠀⠀⠀⠀⠉⠀⠀⠀⢹⠀⠀⢸⠀⠀⢀⣿⠇⠀⠀⠀⠁⠀⢸⠀⠀
⣿⠀⡇⠀⠀⠀⠀⠀⢀⡤⠤⠶⠶⠾⠤⠄⢸⠀⡀⠸⣿⣀⠀⠀⠀⠀⠀⠈⣇⠀
⡇⠀⡇⠀⠀⡀⠀⡴⠋⠀⠀⠀⠀⠀⠀⠀⠸⡌⣵⡀⢳⡇⠀⠀⠀⠀⠀⠀⢹⡀
⡇⠀⠇⠀⠀⡇⡸⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠮⢧⣀⣻⢂⠀⠀⠀⠀⠀⠀⢧
⣇⠀⢠⠀⠀⢳⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡎⣆⠀⠀⠀⠀⠀⠘
⢻⠀⠈⠰⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠘⢮⣧⡀⠀⠀⠀⠀
⠸⡆⠀⠀⠇⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠆⠀⠀⠀⠀⠀⠀⠀⠙⠳⣄⡀⢢⡀
<3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 288 KB Output is correct
11 Correct 93 ms 4948 KB Output is correct
12 Correct 96 ms 5016 KB Output is correct
13 Correct 92 ms 5016 KB Output is correct
14 Correct 76 ms 4948 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 34 ms 6288 KB Output is correct
17 Correct 131 ms 11400 KB Output is correct
18 Correct 110 ms 10804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 34 ms 6288 KB Output is correct
3 Correct 131 ms 11400 KB Output is correct
4 Correct 110 ms 10804 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 212 KB Output is correct
8 Correct 0 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 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 53 ms 2668 KB Output is correct
14 Correct 41 ms 1884 KB Output is correct
15 Correct 25 ms 1492 KB Output is correct
16 Correct 21 ms 1284 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 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 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 288 KB Output is correct
11 Correct 93 ms 4948 KB Output is correct
12 Correct 96 ms 5016 KB Output is correct
13 Correct 92 ms 5016 KB Output is correct
14 Correct 76 ms 4948 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 53 ms 2668 KB Output is correct
24 Correct 41 ms 1884 KB Output is correct
25 Correct 25 ms 1492 KB Output is correct
26 Correct 21 ms 1284 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 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 6288 KB Output is correct
36 Correct 131 ms 11400 KB Output is correct
37 Correct 110 ms 10804 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 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 320 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 4 ms 592 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 18 ms 2020 KB Output is correct
49 Correct 1 ms 324 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 324 KB Output is correct
55 Correct 50 ms 5448 KB Output is correct
56 Correct 34 ms 3276 KB Output is correct
57 Correct 26 ms 3148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 53 ms 2668 KB Output is correct
10 Correct 41 ms 1884 KB Output is correct
11 Correct 25 ms 1492 KB Output is correct
12 Correct 21 ms 1284 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 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 6288 KB Output is correct
22 Correct 131 ms 11400 KB Output is correct
23 Correct 110 ms 10804 KB Output is correct
24 Correct 33 ms 1944 KB Output is correct
25 Correct 75 ms 5024 KB Output is correct
26 Correct 14 ms 1360 KB Output is correct
27 Correct 116 ms 10752 KB Output is correct
28 Correct 105 ms 10764 KB Output is correct
29 Correct 109 ms 10812 KB Output is correct
30 Correct 143 ms 10700 KB Output is correct
31 Correct 232 ms 10808 KB Output is correct
32 Correct 96 ms 6220 KB Output is correct
33 Incorrect 201 ms 11524 KB Output isn't correct
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 288 KB Output is correct
11 Correct 93 ms 4948 KB Output is correct
12 Correct 96 ms 5016 KB Output is correct
13 Correct 92 ms 5016 KB Output is correct
14 Correct 76 ms 4948 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 53 ms 2668 KB Output is correct
24 Correct 41 ms 1884 KB Output is correct
25 Correct 25 ms 1492 KB Output is correct
26 Correct 21 ms 1284 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 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 324 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 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 320 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 4 ms 592 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 18 ms 2020 KB Output is correct
45 Correct 1 ms 324 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 328 KB Output is correct
50 Correct 1 ms 324 KB Output is correct
51 Correct 50 ms 5448 KB Output is correct
52 Correct 34 ms 3276 KB Output is correct
53 Correct 26 ms 3148 KB Output is correct
54 Correct 33 ms 1944 KB Output is correct
55 Correct 75 ms 5024 KB Output is correct
56 Correct 14 ms 1360 KB Output is correct
57 Correct 116 ms 10752 KB Output is correct
58 Correct 105 ms 10764 KB Output is correct
59 Correct 109 ms 10812 KB Output is correct
60 Correct 143 ms 10700 KB Output is correct
61 Correct 232 ms 10808 KB Output is correct
62 Correct 96 ms 6220 KB Output is correct
63 Incorrect 201 ms 11524 KB Output isn't correct
64 Halted 0 ms 0 KB -