답안 #593547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593547 2022-07-11T11:26:15 Z oleh1421 Self Study (JOI22_ho_t2) C++17
100 / 100
229 ms 5244 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#define y2 y_2
#define endl '\n'
#define int ll
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
mt19937 rnd(time(NULL));
const ll mod=998244353;
const int N=600010;
const int Lg=16;
ll a[N],b[N];
ll n,m;
bool ok(ll D){
    ll sum=0ll;
    for (int i=1;i<=n;i++){
        if (a[i]*m>=D){
            sum+=m-(D+a[i]-1)/a[i];
        } else {
            sum-=(D-a[i]*m+b[i]-1)/b[i];
        }
        if (sum+n*m<0) return false;
    }
    return (sum>=0);
}
void solve(){
    cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++) cin>>b[i];
    for (int i=1;i<=n;i++) a[i]=max(a[i],b[i]);
    ll ans=0ll;
    for (ll i=60;i>=0;i--){
        if (ok(ans+(1ll<<i))) ans+=(1ll<<i);
    }
    cout<<ans<<endl;

}
int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt=1;
//    cin>>tt;
    while (tt--){
        solve();
    }
    return 0;

}


/**
3
5 2 7 3 1 6 8 4
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 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 2 ms 340 KB Output is correct
11 Correct 94 ms 5016 KB Output is correct
12 Correct 100 ms 5016 KB Output is correct
13 Correct 93 ms 5016 KB Output is correct
14 Correct 68 ms 4984 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 32 ms 4996 KB Output is correct
17 Correct 128 ms 4956 KB Output is correct
18 Correct 92 ms 5024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 32 ms 4996 KB Output is correct
3 Correct 128 ms 4956 KB Output is correct
4 Correct 92 ms 5024 KB Output is correct
5 Correct 0 ms 340 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 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 57 ms 2632 KB Output is correct
14 Correct 32 ms 1884 KB Output is correct
15 Correct 24 ms 1620 KB Output is correct
16 Correct 21 ms 1280 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 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 2 ms 340 KB Output is correct
11 Correct 94 ms 5016 KB Output is correct
12 Correct 100 ms 5016 KB Output is correct
13 Correct 93 ms 5016 KB Output is correct
14 Correct 68 ms 4984 KB Output is correct
15 Correct 0 ms 340 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 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 57 ms 2632 KB Output is correct
24 Correct 32 ms 1884 KB Output is correct
25 Correct 24 ms 1620 KB Output is correct
26 Correct 21 ms 1280 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 3 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 32 ms 4996 KB Output is correct
36 Correct 128 ms 4956 KB Output is correct
37 Correct 92 ms 5024 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 18 ms 1144 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 60 ms 2544 KB Output is correct
56 Correct 32 ms 1876 KB Output is correct
57 Correct 24 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 57 ms 2632 KB Output is correct
10 Correct 32 ms 1884 KB Output is correct
11 Correct 24 ms 1620 KB Output is correct
12 Correct 21 ms 1280 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 32 ms 4996 KB Output is correct
22 Correct 128 ms 4956 KB Output is correct
23 Correct 92 ms 5024 KB Output is correct
24 Correct 30 ms 1044 KB Output is correct
25 Correct 71 ms 2400 KB Output is correct
26 Correct 13 ms 832 KB Output is correct
27 Correct 94 ms 5008 KB Output is correct
28 Correct 98 ms 5020 KB Output is correct
29 Correct 96 ms 5024 KB Output is correct
30 Correct 122 ms 5024 KB Output is correct
31 Correct 221 ms 4936 KB Output is correct
32 Correct 100 ms 5020 KB Output is correct
33 Correct 197 ms 4936 KB Output is correct
34 Correct 102 ms 5028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 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 2 ms 340 KB Output is correct
11 Correct 94 ms 5016 KB Output is correct
12 Correct 100 ms 5016 KB Output is correct
13 Correct 93 ms 5016 KB Output is correct
14 Correct 68 ms 4984 KB Output is correct
15 Correct 0 ms 340 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 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 57 ms 2632 KB Output is correct
24 Correct 32 ms 1884 KB Output is correct
25 Correct 24 ms 1620 KB Output is correct
26 Correct 21 ms 1280 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 3 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 18 ms 1144 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 60 ms 2544 KB Output is correct
52 Correct 32 ms 1876 KB Output is correct
53 Correct 24 ms 1876 KB Output is correct
54 Correct 30 ms 1044 KB Output is correct
55 Correct 71 ms 2400 KB Output is correct
56 Correct 13 ms 832 KB Output is correct
57 Correct 94 ms 5008 KB Output is correct
58 Correct 98 ms 5020 KB Output is correct
59 Correct 96 ms 5024 KB Output is correct
60 Correct 122 ms 5024 KB Output is correct
61 Correct 221 ms 4936 KB Output is correct
62 Correct 100 ms 5020 KB Output is correct
63 Correct 197 ms 4936 KB Output is correct
64 Correct 102 ms 5028 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 32 ms 4996 KB Output is correct
67 Correct 128 ms 4956 KB Output is correct
68 Correct 92 ms 5024 KB Output is correct
69 Correct 22 ms 724 KB Output is correct
70 Correct 6 ms 340 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 31 ms 972 KB Output is correct
73 Correct 6 ms 468 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 102 ms 5152 KB Output is correct
76 Correct 107 ms 5108 KB Output is correct
77 Correct 130 ms 5068 KB Output is correct
78 Correct 156 ms 5072 KB Output is correct
79 Correct 207 ms 5148 KB Output is correct
80 Correct 229 ms 5208 KB Output is correct
81 Correct 188 ms 5244 KB Output is correct
82 Correct 164 ms 5148 KB Output is correct