Submission #1106029

#TimeUsernameProblemLanguageResultExecution timeMemory
1106029whoknowCloud Computing (CEOI18_clo)C++17
100 / 100
956 ms2244 KiB
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MAXN 2005
#define MAXCORE 100005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
const ll INF = 1e18;
int n, m;
struct arr
{
    int c, f, w;
};
arr a[MAXN], b[MAXN];
namespace sub1
{
int maxc;
ll res;
ll dp[2][MAXCORE];
vector<arr>v;
bool cmp(arr x, arr y)
{
    if(x.f == y.f)
        return x.c > y.c;
    return x.f > y.f;
}
void solve()
{
    for(int i=1;i<=n;i++)
        maxc+=a[i].c;
    for(int i = 1; i <= n; i++)
        v.push_back({a[i].c, a[i].f, -a[i].w});
    for(int i = 1; i <= m; i++)
        v.push_back({-b[i].c, b[i].f, b[i].w});
    sort(v.begin(), v.end(), cmp);
    for(int i=0;i<=1;i++)
        for(int j=0;j<=maxc;j++)
            dp[i][j]=-INF;
    dp[0][0]=0;
    for(int i=0;i<sz(v);i++)
    {
        if(v[i].c>=0)
            dp[1][v[i].c]=v[i].w;
        for(int j=maxc;j>=0;j--)
        {
            int k=j+v[i].c;
            dp[1][j]=max(dp[1][j],dp[0][j]);
            if(k>=0&&k<=maxc&&dp[0][j]<=1e14)
                dp[1][k]=max(dp[1][k],dp[0][j]+v[i].w);
//            cout<<v[i].c<<" "<<v[i].f<<" "<<v[i].w<<" "<<j<<" "<<dp[1][j]<<endl;
        }
        for(int j=0;j<=maxc;j++)
        {
            dp[0][j]=dp[1][j];
            dp[1][j]=-INF;
        }
    }
    for(int k=0;k<=maxc;k++)
        res=max(res,dp[0][k]);
    cout << res;
}
}
main()
{
    if(fopen("TEST.inp", "r"))
    {
        freopen("TESt.inp", "r", stdin);
        freopen("TESt.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i].c >> a[i].f >> a[i].w;
    cin >> m;
    for(int i = 1; i <= m; i++)
        cin >> b[i].c >> b[i].f >> b[i].w;
    sub1::solve();
}
/**

4
20 2550 9999
4 2200 700
4 2000 750
2 1800 10
3
3 2400 4550
6 1900 1500
1 1500 300
**/

Compilation message (stderr)

clo.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
clo.cpp: In function 'int main()':
clo.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("TESt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen("TESt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...