제출 #1275709

#제출 시각아이디문제언어결과실행 시간메모리
1275709zhaoxwCloud Computing (CEOI18_clo)C++20
100 / 100
435 ms2072 KiB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N = 4005;
const int INF = -1e18;
int dp[100005],g[100005],c,f,v,n,m,sum,ans,cnt = 1;
struct unionarray
{
    int uc,uf,uv;
    bool operator<(const unionarray &other)
    {
        if(this->uf > other.uf) return 1;
        else if(this->uf < other.uf) return 0;
        else return this->uc > other.uc;
    }
}a[MAX_N];
signed main()
{
    //freopen("example.in","r",stdin);
    //freopen("example.out","w",stdout);
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> c >> f >> v;
        sum += c;
        a[cnt++] = {c,f,-v};
    }
    cin >> m;
    for(int i = 1;i <= m;i++)
    {
        cin >> c >> f >> v;
        a[cnt++] = {-c,f,v};
    }
    cnt--;
    sort(a+1,a+cnt+1);
    for(int i = 1;i <= sum;i++)
        g[i] = INF;
    for(int i = 1;i <= cnt;i++)
    {
        for(int j = 0;j <= sum;j++)
        {
            dp[j] = INF;
            if(g[j] != INF) dp[j] = g[j];
            if(j-a[i].uc <= sum && j-a[i].uc >= 0 && g[j-a[i].uc] != INF)
                dp[j] = max(dp[j],g[j-a[i].uc]+a[i].uv);
        }
        for(int j = 0;j <= sum;j++)
            g[j] = dp[j];
    }
    for(int i = 0;i <= sum;i++)
        ans = max(ans,dp[i]);
    cout << ans << '\n';
    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...