結果

問題 No.2364 Knapsack Problem
ユーザー umezoumezo
提出日時 2023-06-30 23:16:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 990 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 201,308 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 17:33:41
合計ジャッジ時間 3,248 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
4,380 KB
testcase_01 AC 20 ms
4,380 KB
testcase_02 AC 21 ms
4,380 KB
testcase_03 AC 21 ms
4,380 KB
testcase_04 AC 21 ms
4,380 KB
testcase_05 AC 22 ms
4,380 KB
testcase_06 AC 21 ms
4,380 KB
testcase_07 AC 20 ms
4,384 KB
testcase_08 AC 20 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 20 ms
4,376 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 22 ms
4,380 KB
testcase_13 AC 22 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 21 ms
4,376 KB
testcase_16 AC 22 ms
4,380 KB
testcase_17 AC 22 ms
4,380 KB
testcase_18 AC 22 ms
4,384 KB
testcase_19 AC 21 ms
4,380 KB
testcase_20 AC 21 ms
4,380 KB
testcase_21 AC 21 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const ll INF=1e18;
ll dp1[8][4000],dp2[8][4000];
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m,w;
  cin>>n>>m>>w;
  vector<ll> A(n),B(n),C(m),D(m);
  rep(i,n) cin>>A[i];
  rep(i,n) cin>>B[i];
  rep(i,m) cin>>C[i];
  rep(i,m) cin>>D[i];
  
  rep(i,8) rep(j,4000){
    dp1[i][j]=-INF;
    dp2[i][j]=INF;
  }
  dp1[0][0]=0,dp2[0][0]=0;
  
  rep(i,n){
    rep(j,4000){
      dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
      if(j+A[i]<4000) dp1[i+1][j+A[i]]=max(dp1[i+1][j+A[i]],dp1[i][j]+B[i]);
    }
  }
  rep(i,m){
    rep(j,4000){
      dp2[i+1][j]=min(dp2[i+1][j],dp2[i][j]);
      if(j+C[i]<4000) dp2[i+1][j+C[i]]=min(dp2[i+1][j+C[i]],dp2[i][j]+D[i]);
    }
  }
  ll ma=0;
  rep(i,4000) rep(j,4000){
    if(i-j<0 || i-j>w) continue;
    ma=max(ma,dp1[n][i]-dp2[m][j]);
  }
  cout<<ma<<endl;
  
  return 0;
}
0