Submission #65331311


Source Code Expand

#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>
#include <atcoder/all>
#else
#include <precompile.h>
#endif

using namespace std;
using ll=long long;
using namespace atcoder;
using mint=modint998244353;

#define rep1(i, r) for(int i=0; i<(int)(r); ++i)
#define rep2(i, l, r) for(int i=(l); i<(int)(r); ++i)
#define rep3(i, l, r, d) for(int i=(l); i<(int)(r); i+=(d))
#define rep_r1(i, r) for(int i=(r)-1; i>=0; --i)
#define rep_r2(i, l, r) for(int i=(r)-1; i>=(l); --i)
#define rep_r3(i, l, r, d) for(int i=(r)-1; i>=(l); i-=(d))
#define fifth(a, b, c, d, e, ...) e
#define rep(...) fifth(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rep_r(...) fifth(__VA_ARGS__, rep_r3, rep_r2, rep_r1)(__VA_ARGS__)

template <typename... T>
void in(T &... args) {
    (cin >> ... >> args);
}
template <typename... T>
void in_z(T &... args) {
    (cin >> ... >> args);
    (..., --args);
}
#define in_d(type, ...) type __VA_ARGS__; in(__VA_ARGS__)
#define in_dz(type, ...) type __VA_ARGS__; in_z(__VA_ARGS__)
template <typename It>
void in_i(It first, It last) {
    for(It it=first;it!=last;++it){
        in(*it);
    }
}
template <typename It>
void in_iz(It first, It last) {
    for(It it=first;it!=last;++it){
        in(*it);
        --*it;
    }
}

template <int N>
struct str_literal {
    static constexpr int length=N-1;
    char buf[N];
    constexpr str_literal(const char (&s_literal)[N]){
        rep(i, N){
            buf[i]=s_literal[i];
        }
        buf[length]='\0';
    }
};
template <int N>
ostream & operator<<(ostream & os, const str_literal<N> & str) {
    os << str.buf;
    return os;
}

template <str_literal tail="\n", bool do_flush=false>
void out() {
    cout << tail;
    if(do_flush){
        cout << flush;
    }
}
template <str_literal split=" ", str_literal tail="\n", bool do_flush=false, typename Hd, typename... Tl>
void out(const Hd & hd, const Tl &... tl) {
    cout << hd;
    if constexpr (sizeof...(Tl)){
        (cout << ... << (cout << split, tl));
    }
    cout << tail;
    if(do_flush){
        cout << flush;
    }
}
template <str_literal split=" ", str_literal tail="\n", bool do_flush=false, typename It>
void out_i(It first, It last) {
    for(It it=first;it!=last;++it){
        if(it!=first){
            cout << split;
        }
        cout << *it;
    }
    cout << tail;
    if(do_flush){
        cout << flush;
    }
}

template <str_literal tail="\n", bool do_flush=false>
void err() {
    cerr << tail;
    if(do_flush){
        cout << flush;
    }
}
template <str_literal split=" ", str_literal tail="\n", bool do_flush=false, typename Hd, typename... Tl>
void err(const Hd & hd, const Tl &... tl) {
    cerr << hd;
    if constexpr (sizeof...(Tl)){
        (cerr << ... << (cerr << split, tl));
    }
    cerr << tail;
    if(do_flush){
        cout << flush;
    }
}
template <str_literal split=" ", str_literal tail="\n", bool do_flush=false, typename It>
void err_i(It first, It last) {
    for(It it=first;it!=last;++it){
        if(it!=first){
            cerr << split;
        }
        cerr << *it;
    }
    cerr << tail;
    if(do_flush){
        cout << flush;
    }
}

#define dir(dx, dy) for(auto [dx, dy]: {pair{1, 0}, {0, 1}, {-1, 0}, {0, -1}})
#define dir_8(dx, dy) for(auto [dx, dy]: {pair{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}})

#define all(v) (v).begin(), (v).end()
#define all_r(v) (v).rbegin(), (v).rend()

#define dedup(v) (v).erase(unique(all(v)), (v).end())

#define yn(b) ((b) ? "Yes" : "No")

template <typename T1, typename T2>
bool chmin(T1 & l, const T2 & r) {
    if(r<l){
        l=r;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool chmax(T1 & l, const T2 & r) {
    if(r>l){
        l=r;
        return true;
    }
    return false;
}

template <typename Hd1, typename Hd2, typename... Tl>
auto min_of(Hd1 hd1, Hd2 hd2, Tl... tl) {
    if constexpr (sizeof...(Tl)==0){
        return min(hd1, hd2);
    } else {
        return min(hd1, min_of(hd2, tl...));
    }
}
template <typename Hd1, typename Hd2, typename... Tl>
auto max_of(Hd1 hd1, Hd2 hd2, Tl... tl) {
    if constexpr (sizeof...(Tl)==0){
        return max(hd1, hd2);
    } else {
        return max(hd1, max_of(hd2, tl...));
    }
}
template <typename Hd1, typename Hd2, typename... Tl>
auto gcd_of(Hd1 hd1, Hd2 hd2, Tl... tl) {
    if constexpr (sizeof...(Tl)==0){
        return gcd(hd1, hd2);
    } else {
        return gcd(hd1, gcd_of(hd2, tl...));
    }
}
template <typename Hd1, typename Hd2, typename... Tl>
auto lcm_of(Hd1 hd1, Hd2 hd2, Tl... tl) {
    if constexpr (sizeof...(Tl)==0){
        return lcm(hd1, hd2);
    } else {
        return lcm(hd1, lcm_of(hd2, tl...));
    }
}

template <typename T, size_t N>
auto make_vector(vector<size_t> & sizes, T const& x) {
    if constexpr (N==1){
        return vector(sizes[0], x);
    } else {
        size_t size=sizes[N-1];
        sizes.pop_back();
        return vector(size, make_vector<T, N-1>(sizes, x));
    }
}
template <typename T, size_t N>
auto make_vector(size_t const(&sizes)[N], T const& x=T()) {
    vector<size_t> s(N);
    rep(i, N){
        s[i] = sizes[N-i-1];
    }
    return make_vector<T, N>(s, x);
}
template <typename T, size_t N>
auto make_vector(vector<int> & sizes, T const& x) {
    if constexpr (N==1){
        return vector(sizes[0], x);
    } else {
        int size=sizes[N-1];
        sizes.pop_back();
        return vector(size, make_vector<T, N-1>(sizes, x));
    }
}
template <typename T, size_t N>
auto make_vector(int const(&sizes)[N], T const& x=T()) {
    vector<int> s(N);
    rep(i, N){
        s[i] = sizes[N-i-1];
    }
    return make_vector<T, N>(s, x);
}
template <typename T, size_t Hd, size_t... Tl>
auto make_array() {
    if constexpr (sizeof...(Tl)==0){
        return array<T, Hd>{};
    } else {
        return array<decltype(make_array<T, Tl...>()), Hd>{};
    }
}

constexpr int inf32=1'000'000'001;
constexpr ll inf64=2'000'000'000'000'000'001;

constexpr ll ten_powers[19]={
    1, 10, 100, 1000, 10000, 100000, 1000000,
    10000000, 100000000, 1000000000, 10000000000,
    100000000000, 1000000000000, 10000000000000,
    100000000000000, 1000000000000000,
    10000000000000000, 100000000000000000,
    1000000000000000000
};

template <typename S, S e>
constexpr S e_const() {
    return e;
}
template <typename S1, S1 e1, typename S2, S2 e2>
constexpr pair<S1, S2> e_pair() {
    return {e1, e2};
}
template <typename S>
S op_min(S a, S b) {
    return min(a, b);
}
template <typename S>
S op_max(S a, S b) {
    return max(a, b);
}
template <typename S>
S op_add(S a, S b) {
    return a+b;
}
template <typename S1, typename S2>
pair<S1, S2> op_add_pair(pair<S1, S2> a, pair<S1, S2> b) {
    auto [a1, a2]=a;
    auto [b1, b2]=b;
    return {a1+b1, a2+b2};
}
template <typename F1, typename F2, typename S>
S mapping_affine(pair<F1, F2> f, S x) {
    auto [a, b]=f;
    return a*x+b;
}
template <typename F1, typename F2, typename S1, typename S2>
pair<S1, S2> mapping_len_and_affine(pair<F1, F2> f, pair<S1, S2> x) {
    auto [a, b]=f;
    auto [x1, x2]=x;
    return {x1, a*x2+b*x1};
}
template <typename F1, typename F2>
pair<F1, F2> composition_affine(pair<F1, F2> f, pair<F1, F2> g) {
    auto [a_f, b_f]=f;
    auto [a_g, b_g]=g;
    return {a_f*a_g, a_f*b_g+b_f};
}

template <typename S, S e>
using segtree_min=segtree<S, op_min<S>, e_const<S, e>>;
template <typename S, S e>
using segtree_max=segtree<S, op_max<S>, e_const<S, e>>;
template <typename S>
using segtree_add=segtree<S, op_add<S>, e_const<S, 0>>;
template <typename S, S e>
using lazy_segtree_min=lazy_segtree<S, op_min<S>, e_const<S, e>, pair<S, S>, mapping_affine<S, S, S>, composition_affine<S, S>, e_pair<S, 1, S, 0>>;
template <typename S, S e>
using lazy_segtree_max=lazy_segtree<S, op_max<S>, e_const<S, e>, pair<S, S>, mapping_affine<S, S, S>, composition_affine<S, S>, e_pair<S, 1, S, 0>>;
template <typename S>
using lazy_segtree_add=lazy_segtree<pair<int, S>, op_add_pair<int, S>, e_pair<int, 0, S, 0>, pair<S, S>, mapping_len_and_affine<S, S, int, S>, composition_affine<S, S>, e_pair<S, 1, S, 0>>;

int main(void) {
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
    in_d(int, n);
    vector<tuple<int, int, ll>> dcs(n);
    rep(i, n){
        in_d(int, d, c, s);
        dcs[i]={d, c, s};
    }
    sort(all(dcs), [](auto l, auto r){
        auto [d_l, c_l, s_l]=l;
        auto [d_r, c_r, s_r]=r;
        return tuple{d_l, -c_l, -s_l}<tuple{d_r, -c_r, -s_r};
    });
    auto table=make_vector({n+1, 5001}, 0LL);
    rep(i, n){
        auto [d, c, s]=dcs[i];
        rep(j, 5001){
            chmax(table[i+1][j], table[i][j]);
        }
        rep(j, c, d+1){
            chmax(table[i+1][j], table[i][j-c]+s);
        }
        rep(j, 1, 5001){
            chmax(table[i+1][j], table[i+1][j-1]);
        }
    }
    out(table[n][5000]);
    return 0;
}

Submission Info

Submission Time
Task 011 - Gravy Jobs(★6)
User Not_Leonian
Language C++ 23 (gcc 12.2)
Score 6
Code Size 9252 Byte
Status AC
Exec Time 140 ms
Memory 198916 KiB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 2 / 2 2 / 2 2 / 2
Status
AC × 5
AC × 7
AC × 16
AC × 25
Set Name Test Cases
Sample 00_sample_0_123.txt, 00_sample_1_123.txt, 00_sample_2_123.txt, 00_sample_3__23.txt, 00_sample_4___3.txt
Subtask1 00_sample_0_123.txt, 00_sample_1_123.txt, 00_sample_2_123.txt, 01_random_0_123.txt, 01_random_1_123.txt, 01_random_2_123.txt, 01_random_3_123.txt
Subtask2 00_sample_0_123.txt, 00_sample_1_123.txt, 00_sample_2_123.txt, 00_sample_3__23.txt, 01_random_0_123.txt, 01_random_1_123.txt, 01_random_2_123.txt, 01_random_3_123.txt, 02_random_0__23.txt, 02_random_1__23.txt, 02_random_2__23.txt, 02_random_3__23.txt, 03_maxima_0__23.txt, 03_maxima_1__23.txt, 03_maxima_2__23.txt, 03_maxima_3__23.txt
Subtask3 00_sample_0_123.txt, 00_sample_1_123.txt, 00_sample_2_123.txt, 00_sample_3__23.txt, 00_sample_4___3.txt, 01_random_0_123.txt, 01_random_1_123.txt, 01_random_2_123.txt, 01_random_3_123.txt, 02_random_0__23.txt, 02_random_1__23.txt, 02_random_2__23.txt, 02_random_3__23.txt, 03_maxima_0__23.txt, 03_maxima_1__23.txt, 03_maxima_2__23.txt, 03_maxima_3__23.txt, 04_random_0__3.txt, 04_random_1__3.txt, 04_random_2__3.txt, 04_random_3__3.txt, 05_maxima_0__3.txt, 05_maxima_1__3.txt, 05_maxima_2__3.txt, 05_maxima_3__3.txt
Case Name Status Exec Time Memory
00_sample_0_123.txt AC 1 ms 3716 KiB
00_sample_1_123.txt AC 1 ms 3648 KiB
00_sample_2_123.txt AC 1 ms 3768 KiB
00_sample_3__23.txt AC 2 ms 4016 KiB
00_sample_4___3.txt AC 2 ms 4468 KiB
01_random_0_123.txt AC 1 ms 3912 KiB
01_random_1_123.txt AC 1 ms 3716 KiB
01_random_2_123.txt AC 1 ms 3896 KiB
01_random_3_123.txt AC 1 ms 3716 KiB
02_random_0__23.txt AC 1 ms 4080 KiB
02_random_1__23.txt AC 1 ms 3940 KiB
02_random_2__23.txt AC 1 ms 4016 KiB
02_random_3__23.txt AC 1 ms 4004 KiB
03_maxima_0__23.txt AC 2 ms 4020 KiB
03_maxima_1__23.txt AC 1 ms 3908 KiB
03_maxima_2__23.txt AC 2 ms 3928 KiB
03_maxima_3__23.txt AC 2 ms 4080 KiB
04_random_0__3.txt AC 84 ms 136704 KiB
04_random_1__3.txt AC 45 ms 74500 KiB
04_random_2__3.txt AC 7 ms 13324 KiB
04_random_3__3.txt AC 12 ms 20272 KiB
05_maxima_0__3.txt AC 122 ms 198916 KiB
05_maxima_1__3.txt AC 123 ms 198912 KiB
05_maxima_2__3.txt AC 140 ms 198836 KiB
05_maxima_3__3.txt AC 132 ms 198912 KiB