Submission #914865

# Submission time Handle Problem Language Result Execution time Memory
914865 2024-01-22T19:11:25 Z andrei_iorgulescu Self Study (JOI22_ho_t2) C++14
100 / 100
397 ms 20744 KB
#include <bits/stdc++.h>

using namespace std;

#define int __int128

int n,m,a[300005],b[300005],nev[300005];

int nrparti(int x,int y)
{
    if (x % y == 0)
        return x / y;
    return x / y + 1;
}

bool pot(int x)
{
    int extra = 0;
    for (int i = 1; i <= n; i++)
    {
        nev[i] = x;
        if (a[i] <= b[i])
            extra += m;
        else
        {
            if (x <= m * a[i])
            {
                extra += m - nrparti(x,a[i]);
                nev[i] = 0;
            }
            else
            {
                nev[i] = x - m * a[i];
            }
        }
    }
    for (int i = 1; i <= n; i++)
        extra -= nrparti(nev[i],b[i]);
    if (extra >= 0)
        return true;
    return false;
}

int solvem1()
{
    int ans = 1e9;
    for (int i = 1; i <= n; i++)
        ans = min(ans,max(a[i],b[i]));
    return ans;
}

int solve()
{
    int st = 0,pas = 1ll << 60;
    while (pas != 0)
    {
        if (pot(st + pas) == true)
            st += pas;
        pas /= 2;
    }
    return st;
}

void citire()
{
    long long N,M;
    cin >> N >> M;
    n = N,m = M;
    for (int i = 1; i <= n; i++)
    {
        long long X;
        cin >> X;
        a[i] = X;
    }
    for (int i = 1; i <= n; i++)
    {
        long long X;
        cin >> X;
        b[i] = X;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    citire();
    cout << (long long)solve();
    /*srand(0);
    n = 10;
    m = 1;
    while (true)
    {
        for (int i = 1; i <= n; i++)
            a[i] = b[i] = 1 + rand() % 10;
        if (solvem1() != solve())
        {
            for (int i = 1; i <= n; i++)
                cout << a[i] << ' ';
            cout << endl;
            for (int i = 1; i <= n; i++)
                cout << b[i] << ' ';
        }
    }*/
    return 0;
}

/**
10 1
3 1 1 2 6 1 1 1 1 1
3 1 1 2 6 1 1 1 1 1
**/
# 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 2 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 5 ms 4444 KB Output is correct
11 Correct 321 ms 14540 KB Output is correct
12 Correct 327 ms 14520 KB Output is correct
13 Correct 166 ms 14348 KB Output is correct
14 Correct 242 ms 14288 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 214 ms 14524 KB Output is correct
17 Correct 184 ms 14340 KB Output is correct
18 Correct 182 ms 14524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 214 ms 14524 KB Output is correct
3 Correct 184 ms 14340 KB Output is correct
4 Correct 182 ms 14524 KB Output is correct
5 Correct 1 ms 4440 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 2 ms 4440 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 87 ms 12928 KB Output is correct
14 Correct 60 ms 8824 KB Output is correct
15 Correct 43 ms 8792 KB Output is correct
16 Correct 35 ms 6748 KB Output is correct
17 Correct 1 ms 4440 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 4444 KB Output is correct
23 Correct 4 ms 4700 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 2 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 5 ms 4444 KB Output is correct
11 Correct 321 ms 14540 KB Output is correct
12 Correct 327 ms 14520 KB Output is correct
13 Correct 166 ms 14348 KB Output is correct
14 Correct 242 ms 14288 KB Output is correct
15 Correct 1 ms 4440 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 2 ms 4440 KB Output is correct
20 Correct 2 ms 4696 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 87 ms 12928 KB Output is correct
24 Correct 60 ms 8824 KB Output is correct
25 Correct 43 ms 8792 KB Output is correct
26 Correct 35 ms 6748 KB Output is correct
27 Correct 1 ms 4440 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 4444 KB Output is correct
33 Correct 4 ms 4700 KB Output is correct
34 Correct 1 ms 4440 KB Output is correct
35 Correct 214 ms 14524 KB Output is correct
36 Correct 184 ms 14340 KB Output is correct
37 Correct 182 ms 14524 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
41 Correct 1 ms 4440 KB Output is correct
42 Correct 1 ms 4440 KB Output is correct
43 Correct 1 ms 4540 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 6 ms 4664 KB Output is correct
46 Correct 10 ms 4696 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 55 ms 7748 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 6 ms 4652 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 2 ms 4440 KB Output is correct
55 Correct 159 ms 15804 KB Output is correct
56 Correct 56 ms 10076 KB Output is correct
57 Correct 81 ms 10072 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 2 ms 4440 KB Output is correct
6 Correct 2 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 87 ms 12928 KB Output is correct
10 Correct 60 ms 8824 KB Output is correct
11 Correct 43 ms 8792 KB Output is correct
12 Correct 35 ms 6748 KB Output is correct
13 Correct 1 ms 4440 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 4444 KB Output is correct
19 Correct 4 ms 4700 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 214 ms 14524 KB Output is correct
22 Correct 184 ms 14340 KB Output is correct
23 Correct 182 ms 14524 KB Output is correct
24 Correct 34 ms 7516 KB Output is correct
25 Correct 91 ms 13376 KB Output is correct
26 Correct 20 ms 7260 KB Output is correct
27 Correct 177 ms 20280 KB Output is correct
28 Correct 179 ms 20096 KB Output is correct
29 Correct 192 ms 20336 KB Output is correct
30 Correct 193 ms 20308 KB Output is correct
31 Correct 224 ms 20224 KB Output is correct
32 Correct 237 ms 15672 KB Output is correct
33 Correct 240 ms 20744 KB Output is correct
34 Correct 240 ms 15700 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 2 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 5 ms 4444 KB Output is correct
11 Correct 321 ms 14540 KB Output is correct
12 Correct 327 ms 14520 KB Output is correct
13 Correct 166 ms 14348 KB Output is correct
14 Correct 242 ms 14288 KB Output is correct
15 Correct 1 ms 4440 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 2 ms 4440 KB Output is correct
20 Correct 2 ms 4696 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 87 ms 12928 KB Output is correct
24 Correct 60 ms 8824 KB Output is correct
25 Correct 43 ms 8792 KB Output is correct
26 Correct 35 ms 6748 KB Output is correct
27 Correct 1 ms 4440 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 4444 KB Output is correct
33 Correct 4 ms 4700 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 ms 4440 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4540 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 6 ms 4664 KB Output is correct
42 Correct 10 ms 4696 KB Output is correct
43 Correct 2 ms 4444 KB Output is correct
44 Correct 55 ms 7748 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 6 ms 4652 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 2 ms 4440 KB Output is correct
51 Correct 159 ms 15804 KB Output is correct
52 Correct 56 ms 10076 KB Output is correct
53 Correct 81 ms 10072 KB Output is correct
54 Correct 34 ms 7516 KB Output is correct
55 Correct 91 ms 13376 KB Output is correct
56 Correct 20 ms 7260 KB Output is correct
57 Correct 177 ms 20280 KB Output is correct
58 Correct 179 ms 20096 KB Output is correct
59 Correct 192 ms 20336 KB Output is correct
60 Correct 193 ms 20308 KB Output is correct
61 Correct 224 ms 20224 KB Output is correct
62 Correct 237 ms 15672 KB Output is correct
63 Correct 240 ms 20744 KB Output is correct
64 Correct 240 ms 15700 KB Output is correct
65 Correct 1 ms 4440 KB Output is correct
66 Correct 214 ms 14524 KB Output is correct
67 Correct 184 ms 14340 KB Output is correct
68 Correct 182 ms 14524 KB Output is correct
69 Correct 42 ms 7256 KB Output is correct
70 Correct 10 ms 4844 KB Output is correct
71 Correct 1 ms 4444 KB Output is correct
72 Correct 59 ms 7516 KB Output is correct
73 Correct 13 ms 4696 KB Output is correct
74 Correct 2 ms 4444 KB Output is correct
75 Correct 328 ms 20308 KB Output is correct
76 Correct 332 ms 20304 KB Output is correct
77 Correct 338 ms 20224 KB Output is correct
78 Correct 363 ms 20308 KB Output is correct
79 Correct 397 ms 20304 KB Output is correct
80 Correct 396 ms 20304 KB Output is correct
81 Correct 226 ms 18344 KB Output is correct
82 Correct 245 ms 18344 KB Output is correct