Submission #794408

# Submission time Handle Problem Language Result Execution time Memory
794408 2023-07-26T14:00:35 Z Theo830 Self Study (JOI22_ho_t2) C++17
100 / 100
279 ms 11512 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll l = 0,r = 1e18;
    ll ans = 0;
    ll n,m;
    cin>>n>>m;
    ll a[n],b[n];
    f(i,0,n){
        cin>>a[i];
    }
    f(i,0,n){
        cin>>b[i];
    }
    while(l <= r){
        ll mid = (l+r)/2;
        ll A = 0,B = 0;
        f(i,0,n){
            if(b[i] >= a[i]){
                B += (mid + b[i] - 1) / b[i];
            }
            else{
                ll posa = min(m,(mid + a[i] - 1) / a[i]);
                A += posa;
                ll num = max(0LL,mid - posa * a[i]);
                B += (num + b[i] - 1) / b[i];
            }
            if(A + B > n * m){
                break;
            }
        }
        if(A + B <= n*m){
            l = mid + 1;
            ans = max(ans,mid);
        }
        else{
            r = mid - 1;
        }
    }
    cout<<ans<<"\n";
}
# Verdict Execution time Memory 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 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 100 ms 4948 KB Output is correct
12 Correct 99 ms 5000 KB Output is correct
13 Correct 67 ms 4948 KB Output is correct
14 Correct 78 ms 4988 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 27 ms 4948 KB Output is correct
17 Correct 78 ms 4992 KB Output is correct
18 Correct 79 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 27 ms 4948 KB Output is correct
3 Correct 78 ms 4992 KB Output is correct
4 Correct 79 ms 4948 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 47 ms 2760 KB Output is correct
14 Correct 28 ms 1848 KB Output is correct
15 Correct 20 ms 1496 KB Output is correct
16 Correct 17 ms 1236 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 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 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory 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 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 100 ms 4948 KB Output is correct
12 Correct 99 ms 5000 KB Output is correct
13 Correct 67 ms 4948 KB Output is correct
14 Correct 78 ms 4988 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 47 ms 2760 KB Output is correct
24 Correct 28 ms 1848 KB Output is correct
25 Correct 20 ms 1496 KB Output is correct
26 Correct 17 ms 1236 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 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 0 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 27 ms 4948 KB Output is correct
36 Correct 78 ms 4992 KB Output is correct
37 Correct 79 ms 4948 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 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 0 ms 320 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 4 ms 632 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 18 ms 2012 KB Output is correct
49 Correct 0 ms 212 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 324 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 55 ms 5432 KB Output is correct
56 Correct 26 ms 3028 KB Output is correct
57 Correct 27 ms 3028 KB Output is correct
# Verdict Execution time Memory 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 47 ms 2760 KB Output is correct
10 Correct 28 ms 1848 KB Output is correct
11 Correct 20 ms 1496 KB Output is correct
12 Correct 17 ms 1236 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 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 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 27 ms 4948 KB Output is correct
22 Correct 78 ms 4992 KB Output is correct
23 Correct 79 ms 4948 KB Output is correct
24 Correct 26 ms 1924 KB Output is correct
25 Correct 62 ms 5000 KB Output is correct
26 Correct 11 ms 1416 KB Output is correct
27 Correct 81 ms 10752 KB Output is correct
28 Correct 86 ms 10812 KB Output is correct
29 Correct 87 ms 10804 KB Output is correct
30 Correct 107 ms 10752 KB Output is correct
31 Correct 181 ms 10800 KB Output is correct
32 Correct 105 ms 6172 KB Output is correct
33 Correct 211 ms 11512 KB Output is correct
34 Correct 105 ms 6164 KB Output is correct
# Verdict Execution time Memory 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 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 100 ms 4948 KB Output is correct
12 Correct 99 ms 5000 KB Output is correct
13 Correct 67 ms 4948 KB Output is correct
14 Correct 78 ms 4988 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 47 ms 2760 KB Output is correct
24 Correct 28 ms 1848 KB Output is correct
25 Correct 20 ms 1496 KB Output is correct
26 Correct 17 ms 1236 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 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 0 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 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 0 ms 320 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 3 ms 460 KB Output is correct
42 Correct 4 ms 632 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 18 ms 2012 KB Output is correct
45 Correct 0 ms 212 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 324 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 55 ms 5432 KB Output is correct
52 Correct 26 ms 3028 KB Output is correct
53 Correct 27 ms 3028 KB Output is correct
54 Correct 26 ms 1924 KB Output is correct
55 Correct 62 ms 5000 KB Output is correct
56 Correct 11 ms 1416 KB Output is correct
57 Correct 81 ms 10752 KB Output is correct
58 Correct 86 ms 10812 KB Output is correct
59 Correct 87 ms 10804 KB Output is correct
60 Correct 107 ms 10752 KB Output is correct
61 Correct 181 ms 10800 KB Output is correct
62 Correct 105 ms 6172 KB Output is correct
63 Correct 211 ms 11512 KB Output is correct
64 Correct 105 ms 6164 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 27 ms 4948 KB Output is correct
67 Correct 78 ms 4992 KB Output is correct
68 Correct 79 ms 4948 KB Output is correct
69 Correct 23 ms 1364 KB Output is correct
70 Correct 6 ms 468 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 34 ms 1748 KB Output is correct
73 Correct 7 ms 596 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 110 ms 10872 KB Output is correct
76 Correct 122 ms 10740 KB Output is correct
77 Correct 134 ms 10736 KB Output is correct
78 Correct 174 ms 10744 KB Output is correct
79 Correct 234 ms 10816 KB Output is correct
80 Correct 236 ms 10752 KB Output is correct
81 Correct 195 ms 8816 KB Output is correct
82 Correct 279 ms 8936 KB Output is correct