Submission #70777129


Source Code Expand

/*
  Compete against Yourself.
  Author - Aryan (@aryanc403)
*/
/*
  Credits -
  Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ (namespace atcoder)
  Github source code of library - https://github.com/atcoder/ac-library/tree/master/atcoder
  https://codeforces.com/contest/4/submission/150120627
*/

#ifdef ARYANC403
    #include <header.h>
#else
    #pragma GCC optimize ("Ofast")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
    #pragma GCC target ("sse,sse2,mmx")
    #pragma GCC optimize ("-ffloat-store")
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define dbg(args...) 42;
    #define endl "\n"
#endif

// y_combinator from @neal template https://codeforces.com/contest/1553/submission/123849801
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define eb emplace_back
#define X first
#define Y second

using lli = long long int;
using mytype = long double;
using ii = pair<lli,lli>;
using vii = vector<ii>;
using vi = vector<lli>;

template <class T>
using ordered_set =  __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
// X.find_by_order(k) return kth element. 0 indexed.
// X.order_of_key(k) returns count of elements strictly less than k.

// namespace Re = std::ranges;
// namespace Ve = std::ranges::views;

const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
}

const lli INF = 0xFFFFFFFFFFFFFFFLL;
const lli SEED=chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(SEED);
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

using t3 = array<lli,3>;
const lli L = 500*500+5,MX=2*L;

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// Ve::iota(1, 6) | Ve::transform([](int x) { return x * 2; }) | Ve::reverse | Ve::take(3)
lli T=1;
// cin>>T;
while(T--)
{
    lli n=500;
    cin>>n;
    vector<t3> a(n);
    for(auto &v:a){
        v[0]=500;
        v[1]=rnd();
        v[2]=rnd();
        cin>>v[0]>>v[1]>>v[2];
    }

    vi dp(MX+1,-INF);
    dp[L]=0;
    for(const auto &v:a){
        const lli w=v[0],h=v[1],b=v[2];
        vi ndp(2*L+1,-INF);
        for(lli j=0;j<=MX;j++){
            if(j+w<=MX)
                ndp[j+w]=max(ndp[j+w],dp[j]+b);
            if(j-w>=0)
                ndp[j-w]=max(ndp[j-w],dp[j]+h);
        }
        dp=ndp;
    }

    lli ans = -INF;
    for(lli j=L;j<=MX;j++)
        ans=max(ans,dp[j]);
    cout<<ans<<endl;

}   aryanc403();
    return 0;
}

Submission Info

Submission Time
Task D - Robot Customize
User aryanc403
Language C++23 (GCC 15.2.0)
Score 400
Code Size 4240 Byte
Status AC
Exec Time 408 ms
Memory 11340 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 54
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 9 ms 11200 KiB
00_sample_01.txt AC 5 ms 11100 KiB
00_sample_02.txt AC 7 ms 11236 KiB
00_sample_03.txt AC 21 ms 11264 KiB
01_random_03.txt AC 406 ms 11340 KiB
01_random_04.txt AC 407 ms 11284 KiB
01_random_05.txt AC 405 ms 11304 KiB
01_random_06.txt AC 404 ms 11264 KiB
01_random_07.txt AC 404 ms 11236 KiB
01_random_08.txt AC 406 ms 11340 KiB
01_random_09.txt AC 408 ms 11296 KiB
01_random_10.txt AC 406 ms 11292 KiB
01_random_11.txt AC 405 ms 11292 KiB
01_random_12.txt AC 318 ms 11244 KiB
01_random_13.txt AC 195 ms 11284 KiB
01_random_14.txt AC 177 ms 11268 KiB
01_random_15.txt AC 244 ms 11292 KiB
01_random_16.txt AC 148 ms 11148 KiB
01_random_17.txt AC 407 ms 11244 KiB
01_random_18.txt AC 406 ms 11280 KiB
01_random_19.txt AC 406 ms 11220 KiB
01_random_20.txt AC 405 ms 11196 KiB
01_random_21.txt AC 406 ms 11296 KiB
01_random_22.txt AC 178 ms 11292 KiB
01_random_23.txt AC 24 ms 11216 KiB
01_random_24.txt AC 10 ms 11244 KiB
01_random_25.txt AC 405 ms 11292 KiB
01_random_26.txt AC 405 ms 11280 KiB
01_random_27.txt AC 406 ms 11240 KiB
01_random_28.txt AC 405 ms 11284 KiB
01_random_29.txt AC 402 ms 11264 KiB
01_random_30.txt AC 399 ms 11340 KiB
01_random_31.txt AC 342 ms 11292 KiB
01_random_32.txt AC 235 ms 11204 KiB
01_random_33.txt AC 5 ms 11044 KiB
01_random_34.txt AC 5 ms 11168 KiB
01_random_35.txt AC 403 ms 11204 KiB
01_random_36.txt AC 402 ms 11224 KiB
01_random_37.txt AC 403 ms 11292 KiB
01_random_38.txt AC 404 ms 11264 KiB
01_random_39.txt AC 402 ms 11212 KiB
01_random_40.txt AC 402 ms 11284 KiB
01_random_41.txt AC 402 ms 11204 KiB
01_random_42.txt AC 403 ms 11212 KiB
01_random_43.txt AC 248 ms 11276 KiB
01_random_44.txt AC 368 ms 11264 KiB
01_random_45.txt AC 334 ms 11284 KiB
01_random_46.txt AC 82 ms 11148 KiB
01_random_47.txt AC 207 ms 11220 KiB
01_random_48.txt AC 402 ms 11340 KiB
01_random_49.txt AC 402 ms 11240 KiB
01_random_50.txt AC 402 ms 11264 KiB
01_random_51.txt AC 52 ms 11200 KiB
01_random_52.txt AC 167 ms 11340 KiB