이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define int long long
const int N=1e5+9;
const int oo=1e17;
int f[2][N];
struct computer
{
int c,f,val;
}a[N];
bool compa(computer a,computer b)
{
if (a.f==b.f) return a.c>b.c;
return a.f>b.f;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
//freopen("test.inp","r",stdin);
int n,m;
cin>>n;
int sum=0;
for (int i=1;i<=n;i++)
{
cin>>a[i].c>>a[i].f>>a[i].val;
a[i].val=-a[i].val;
sum+=a[i].c;
}
cin>>m;
for (int i=n+1;i<=n+m;i++)
{
cin>>a[i].c>>a[i].f>>a[i].val;
a[i].c=-a[i].c;
}
n+=m;
sort(a+1,a+1+n,compa);
for (int j=0;j<=sum+52;j++)
f[0][j]=-oo;
f[0][0]=0;
int res=0;
for (int i=1;i<=n;i++)
{
int now=i&1;
int past=(i-1)&1;
for (int j=0;j<=sum+52;j++)
f[now][j]=-oo;
for (int j=0;j<=sum;j++)
{
f[now][j]=f[past][j];
if (j-a[i].c>=0) f[now][j]=max(f[now][j],f[past][j-a[i].c]+a[i].val);
if (i==n) res=max(res,f[now][j]);
}
}
cout<<res;
return 0;
}
# | 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... |