이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
ll v=x.nd.nd;
if(c>0)
{
for(int j=0;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=0;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 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... |