# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1106029 | whoknow | Cloud Computing (CEOI18_clo) | C++17 | 956 ms | 2244 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |