제출 #725475

#제출 시각아이디문제언어결과실행 시간메모리
725475Rafi22Cloud Computing (CEOI18_clo)C++14
18 / 100
526 ms2004 KiB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

ll DP[2][2007*57];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector<pair<int,pair<int,int>>>V;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int c,f,v;
        cin>>c>>f>>v;
        V.pb({f,{c,v}});
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int c,f,v;
        cin>>c>>f>>v;
        V.pb({f,{-c,v}});
    }
    sort(all(V),greater<pair<int,pair<int,int>>>());
    for(int i=1;i<=n*50;i++) DP[0][i]=-infl;
    int i=0;
    for(auto x:V)
    {
        i++;
        int c=x.nd.st,v=x.nd.nd;
        if(c>0)
        {
            for(int j=1;j<=n*50;j++)
            {
                DP[i%2][j]=DP[(i-1)%2][j];
                if(j-c>=0) DP[i%2][j]=max(DP[i%2][j],DP[(i-1)%2][j-c]-v);
            }
        }
        else
        {
            c=-c;
            for(int j=1;j<=n*50;j++)
            {
                DP[i%2][j]=DP[(i-1)%2][j];
                if(j+c<=n*50) DP[i%2][j]=max(DP[i%2][j],DP[(i-1)%2][j+c]+v);
            }
        }
    }
    ll ans=0;
    for(int j=0;j<=n*50;j++) ans=max(ans,DP[i%2][j]);
    cout<<ans;

    return 0;
}
#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...