結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー ninesnines
提出日時 2024-03-22 23:11:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 9,345 bytes
コンパイル時間 3,520 ms
コンパイル使用メモリ 258,472 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-30 12:26:16
合計ジャッジ時間 8,278 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 1 ms
6,820 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 2 ms
6,820 KB
testcase_05 AC 2 ms
6,816 KB
testcase_06 AC 1 ms
6,816 KB
testcase_07 AC 2 ms
6,816 KB
testcase_08 AC 2 ms
6,816 KB
testcase_09 AC 1 ms
6,816 KB
testcase_10 AC 1 ms
6,816 KB
testcase_11 AC 2 ms
6,820 KB
testcase_12 AC 2 ms
6,820 KB
testcase_13 AC 2 ms
6,816 KB
testcase_14 AC 2 ms
6,816 KB
testcase_15 AC 1 ms
6,820 KB
testcase_16 AC 2 ms
6,816 KB
testcase_17 AC 2 ms
6,816 KB
testcase_18 AC 2 ms
6,816 KB
testcase_19 AC 1 ms
6,820 KB
testcase_20 AC 2 ms
6,820 KB
testcase_21 AC 2 ms
6,820 KB
testcase_22 WA -
testcase_23 AC 1 ms
6,820 KB
testcase_24 AC 17 ms
6,820 KB
testcase_25 AC 14 ms
6,816 KB
testcase_26 AC 20 ms
6,824 KB
testcase_27 AC 26 ms
6,816 KB
testcase_28 AC 29 ms
6,912 KB
testcase_29 AC 10 ms
6,816 KB
testcase_30 AC 47 ms
9,216 KB
testcase_31 AC 26 ms
6,820 KB
testcase_32 AC 49 ms
9,472 KB
testcase_33 AC 47 ms
9,344 KB
testcase_34 AC 4 ms
6,816 KB
testcase_35 AC 24 ms
6,820 KB
testcase_36 AC 31 ms
7,296 KB
testcase_37 AC 54 ms
10,112 KB
testcase_38 AC 35 ms
7,680 KB
testcase_39 AC 8 ms
6,816 KB
testcase_40 AC 26 ms
6,820 KB
testcase_41 AC 12 ms
6,820 KB
testcase_42 AC 2 ms
6,820 KB
testcase_43 AC 5 ms
6,816 KB
testcase_44 AC 53 ms
10,240 KB
testcase_45 AC 54 ms
10,240 KB
testcase_46 AC 17 ms
6,820 KB
testcase_47 AC 17 ms
6,816 KB
testcase_48 AC 29 ms
7,040 KB
testcase_49 AC 47 ms
10,880 KB
testcase_50 AC 46 ms
11,008 KB
testcase_51 AC 45 ms
10,880 KB
testcase_52 AC 46 ms
10,880 KB
testcase_53 AC 48 ms
10,880 KB
testcase_54 AC 60 ms
10,880 KB
testcase_55 AC 60 ms
11,008 KB
testcase_56 AC 62 ms
10,880 KB
testcase_57 AC 61 ms
11,008 KB
testcase_58 AC 61 ms
10,880 KB
testcase_59 AC 62 ms
10,880 KB
testcase_60 AC 62 ms
10,880 KB
testcase_61 AC 61 ms
10,880 KB
testcase_62 AC 61 ms
11,008 KB
testcase_63 AC 61 ms
10,880 KB
testcase_64 AC 61 ms
10,880 KB
testcase_65 AC 61 ms
10,880 KB
testcase_66 AC 61 ms
10,880 KB
testcase_67 AC 61 ms
10,880 KB
testcase_68 AC 61 ms
10,880 KB
testcase_69 AC 52 ms
11,008 KB
testcase_70 AC 52 ms
10,880 KB
testcase_71 AC 53 ms
10,880 KB
testcase_72 AC 51 ms
10,880 KB
testcase_73 AC 51 ms
10,880 KB
testcase_74 AC 26 ms
7,168 KB
testcase_75 AC 51 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/string>
// #include <atcoder/math>
// #include <atcoder/scc>
// #include <atcoder/dsu>
// using namespace atcoder;

// #include <atcoder/modint>
// using mint = atcoder::modint998244353;
// using mint = atcoder::modint1000000007;
// using mint = atcoder::modint;

// #include <boost/multiprecision/cpp_int.hpp>
// using Bint = boost::multiprecision::cpp_int;

// #include <boost/rational.hpp>
// using Rat = boost::rational<Bint>;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// using Real = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1024>>;

#ifdef LOCAL
#include <library/debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

using ll = long long;
using ld = long double;
const ll INF = 4e18;
const int INF_INT = 2e9;

using vi = vector<int>;
using vd = vector<double>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vp = vector<pair<ll, ll>>;
using vpc = vector<pair<char, ll>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pl = pair<ll, ll>;

template <class T>
using PQ = priority_queue<T>;
template <class T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} fast;

// interactive
#define endl "\n"

#define INTYPE(type, ...) type __VA_ARGS__;
#define INT(...) INTYPE(int, __VA_ARGS__) IN(__VA_ARGS__)
#define LL(...) INTYPE(ll, __VA_ARGS__) IN(__VA_ARGS__)
#define STR(...) INTYPE(string, __VA_ARGS__) IN(__VA_ARGS__)
#define CHR(...) INTYPE(char, __VA_ARGS__) IN(__VA_ARGS__)
#define DBL(...) INTYPE(double, __VA_ARGS__) IN(__VA_ARGS__)
#define LD(...) INTYPE(ld, __VA_ARGS__) IN(__VA_ARGS__)

#define overload6(_1, _2, _3, _4, _5, _6, name, ...) name
#define INVEC(type, ...) vector<type> __VA_ARGS__;
#define VEC1(type, name, size) INVEC(type, name(size)) rep(I, size) IN(name[I])
#define VEC2(type, name1, name2, size) INVEC(type, name1(size), name2(size)) rep(I, size) IN(name1[I], name2[I])
#define VEC3(type, name1, name2, name3, size) INVEC(type, name1(size), name2(size), name3(size)) rep(I, size) IN(name1[I], name2[I], name3[I])
#define VEC4(type, name1, name2, name3, name4, size) INVEC(type, name1(size), name2(size), name3(size), name4(size)) rep(I, size) IN(name1[I], name2[I], name3[I], name4[I]);
#define VEC(...) overload6(__VA_ARGS__, VEC4, VEC3, VEC2, VEC1)(__VA_ARGS__)
#define VV(type, name, h, w) INVEC(vector<type>, name(h, vector<type>(w))) rep(I, h) rep(J, w) IN(name[I][J]);

#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(i, n) rep2(i, 0, n)
#define rep2(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define rep3(i, a, b, c) for (ll i = ll(a); i < ll(b); i += ll(c))
#define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(i, n) rrep2(i, 0, n)
#define rrep2(i, a, b) for (ll i = ll(b) - 1; i >= ll(a); --i)
#define rrep3(i, a, b, c) for (ll i = ll(b) - 1; i >= ll(a); i -= ll(c))
#define rrep(...) overload4(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define llacumulate(v) accumulate(all(v), 0LL)
#define sz(x) (ll)(x).size()
#define ctoi(c) (c - '0')
#define itoc(i) (i + '0')
#define emp(x) x.empty()
#define nmod(x, m) ((x % m + m) % m)

#define fi first
#define se second
#define pf push_front
#define ef emplace_front
#define pof pop_front
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define pc (ll) __builtin_popcountll

#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;

bool yn(bool f) {
    cout << (f ? "Yes" : "No") << endl;
    return f;
}
bool YN(bool f) {
    cout << (f ? "YES" : "NO") << endl;
    return f;
}
bool kaibun(string s) { return s == string(rall(s)); }
bool inGrid(ll i, ll j, ll h, ll w) { return i < h && j < w && i >= 0 && j >= 0; }

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

template <class... T>
void IN(T &...a) {
    (cin >> ... >> a);
}

string toUpper(string s) {
    rep(i, s.size()) s[i] = toupper(s[i]);
    return s;
}
string toLower(string s) {
    rep(i, s.size()) s[i] = tolower(s[i]);
    return s;
}

template <class T>
auto min(const T &a) { return *min_element(all(a)); }
template <class T>
auto max(const T &a) { return *max_element(all(a)); }

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<pair<char, ll>> runLength(const string &str) {
    ll n = str.size();
    vector<pair<char, ll>> res;
    for (ll l = 0; l < n;) {
        ll r = l + 1;
        while (r < n && str[l] == str[r])
            ++r;
        res.emplace_back(str[l], r - l);
        l = r;
    }
    return res;
}

template <typename T, typename S>
int getNearest(const T &a, const vector<S> &v) {
    int x = lower_bound(all(v), a) - v.begin(), n = v.size();
    if (x == 0)
        return 0;
    if (x == n)
        return n - 1;
    if (abs(v[x] - a) < abs(v[x - 1] - a))
        return x;
    else
        return x - 1;
}

template <typename T>
vector<pair<ll, ll>> primeFactorize(T n) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i != 0)
            continue;
        ll cnt = 0;
        while (n % i == 0) {
            n /= i;
            ++cnt;
        }
        res.emplace_back(i, cnt);
    }
    if (n != 1)
        res.emplace_back(n, 1);
    return res;
}

template <typename T>
bool isPrime(const T &n) {
    if (n < 2)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (ll i = 3; i * i <= n; ++i)
        if (n % i == 0)
            return false;
    return true;
}

vector<bool> eratosthenes(ll n) {
    vector<bool> v(n + 1, true);
    v[0] = v[1] = false;
    for (ll p = 2; p <= n; ++p) {
        if (!v[p])
            continue;
        for (ll q = p * 2; q <= n; q += p)
            v[q] = false;
    }
    return v;
}

template <typename T>
vector<ll> divisor(T n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i * i != n)
                res.emplace_back(n / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

ll llpow(ll x, ll n) {
    if (n == 0)
        return 1;
    ll res = llpow(x, n / 2);
    res *= res;
    if (n % 2 == 1)
        res *= x;
    return res;
}

template <typename T, typename S>
T getCycle(const vector<T> &v, const S &k) {
    T n = v.size(), s = v.back(), i;
    for (i = n - 2; i >= 0; --i) {
        if (v[i] == s)
            break;
    }
    if (k < i)
        return v[k];
    else
        return v[i + (k - i) % (n - i - 1)];
}

void print() { cout << endl; }
template <typename T>
inline void print(const T &x) { cout << x << endl; }
template <class T, class... Ts>
void print(const T &a, const Ts &...b) {
    cout << a;
    (cout << ... << (cout << ' ', b));
    cout << endl;
}
template <typename T>
inline void print(const vector<T> &v) {
    rep(i, v.size()) {
        if (i != (ll)v.size() - 1)
            cout << v[i] << " ";
        else
            cout << v[i] << endl;
    }
}
template <typename T>
inline void print(const vector<vector<T>> &v) {
    for (auto &&p : v)
        print(p);
}
template <typename T, typename S>
inline void print(const pair<T, S> &p) {
    cout << p.first << " " << p.second << endl;
}
template <typename T, typename S>
inline void print(const vector<pair<T, S>> &v) {
    for (auto &&p : v)
        print(p);
}

int main() {
    LL(n, h);
    VEC(ll, a, n);
    VEC(ll, b, n);

    vl na(n + 1);
    rep(i, n) na[i + 1] = na[i] + a[i];
    vl nb(n + 1);
    rep(i, n) nb[i + 1] = nb[i] + b[i];
    debug(na, nb);

    rep(i, n) b[i] *= (i + 1);
    vl nb2(n + 1);
    rep(i, n) nb2[i + 1] = nb2[i] + b[i];

    auto check = [&](ll l, ll r) -> bool {
        return nb2[r + 1] - nb2[l] - l * (nb[r + 1] - nb[l]) <= h;
    };

    ll ans = 0;
    auto f = [&](ll start) {
        ll ok = start, ng = n;
        while (ng - ok > 1) {
            ll mid = (ng + ok) / 2;
            debug(mid);

            if (check(start, mid))
                ok = mid;
            else
                ng = mid;
        }
        debug(start, ok);

        if (start == ok) {
            if (b[start] <= h)
                chmax(ans, a[start]);
        } else {
            chmax(ans, na[ok + 1] - na[start]);
        }
    };

    rep(i, n) f(i);
    print(ans);
}
0