Submission #698414

# Submission time Handle Problem Language Result Execution time Memory
698414 2023-02-13T11:58:26 Z Danilo21 Self Study (JOI22_ho_t2) C++14
0 / 100
473 ms 5052 KB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 1e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, m, a[mxN], b[mxN];

bool Check(ll k){

    ll cnt = 0;
    for (int i = 0; i < n; i++){
        ll cur = k;
        if (a[i] > b[i]){
            ll x = (k + a[i] - 1)/a[i];
            smin(x, m);
            cur -= min(cur, x*a[i]);
            cnt += x;
        }
        ll x = (cur + b[i] - 1)/b[i];
        cnt += x;
    }
    return cnt <= n*m;
}

void Solve(){

    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    ll l = 1, r = LINF, ans = 0;
    while (l <= r){
        ll k = (l + r + 1)>>1;
        if (Check(k)){
            ans = k;
            l = k + 1;
        }
        else r = k - 1;
    }
    cout << ans << en;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 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 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 215 ms 5052 KB Output is correct
12 Correct 208 ms 5020 KB Output is correct
13 Correct 150 ms 5020 KB Output is correct
14 Incorrect 473 ms 5016 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 280 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 82 ms 2668 KB Output is correct
10 Correct 53 ms 1896 KB Output is correct
11 Correct 43 ms 1596 KB Output is correct
12 Correct 33 ms 1252 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 5 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 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 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 215 ms 5052 KB Output is correct
12 Correct 208 ms 5020 KB Output is correct
13 Correct 150 ms 5020 KB Output is correct
14 Incorrect 473 ms 5016 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 280 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 82 ms 2668 KB Output is correct
10 Correct 53 ms 1896 KB Output is correct
11 Correct 43 ms 1596 KB Output is correct
12 Correct 33 ms 1252 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 5 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 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 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 215 ms 5052 KB Output is correct
12 Correct 208 ms 5020 KB Output is correct
13 Correct 150 ms 5020 KB Output is correct
14 Incorrect 473 ms 5016 KB Output isn't correct
15 Halted 0 ms 0 KB -