Submission #552811

#TimeUsernameProblemLanguageResultExecution timeMemory
552811CyberSleeperCloud Computing (CEOI18_clo)C++17
100 / 100
704 ms2236 KiB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x)      x.begin(), x.end()
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ull         unsigned long long
#define pll         pair<ll, ll>
#define pii         pair<int, int>
#define ld          long double
#define nl          endl
#define tb          '\t'
#define sp          ' '
#define sqr(x)      (x)*(x)
#define arr3        array<ll, 3>
using namespace std;
 
const ll MX=2005, MOD=1000000007, BLOCK=160, INF=2e9+7, LG=62;
const ll INFF=1000000000000000007;
const ld ERR=1e-6, pi=3.14159265358979323846;
 
ll N, DP[2][50*MX];
vector<arr3> A;
 
int main(){
    fastio;
    cin >> N;
    for(ll i=0, c, f, v; i<N; i++){
        cin >> c >> f >> v;
        A.pb({f, c, -v});
    }
    cin >> N;
    for(ll i=0, c, f, v; i<N; i++){
        cin >> c >> f >> v;
        A.pb({f, -c, v});
    }
    N=A.size();
    A.pb({INF, INF, INF});
    sort(all(A), greater<arr3>());
    for(int j=1; j<=100000; j++)
        DP[0][j]=-INFF;
    DP[0][0]=0;
    for(int i=1, now, bef; i<=N; i++){
        now=i%2, bef=now^1;
        for(int j=0; j<=100000; j++){
            DP[now][j]=DP[bef][j];
            if(j-A[i][1]>=0 && j-A[i][1]<=100000 && DP[bef][j-A[i][1]]!=INFF){
                DP[now][j]=max(DP[now][j], DP[bef][j-A[i][1]]+A[i][2]);
            }
        }
    }
    N%=2;
    for(int i=1; i<=100000; i++)
        DP[N][0]=max(DP[N][0], DP[N][i]);
    cout << DP[N][0] << nl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...