結果

問題 No.2741 Balanced Choice
ユーザー butsurizukibutsurizuki
提出日時 2024-04-21 02:57:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 3,435 ms
コンパイル使用メモリ 275,412 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 02:57:53
合計ジャッジ時間 4,312 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
6,816 KB
testcase_01 AC 30 ms
6,944 KB
testcase_02 AC 29 ms
6,944 KB
testcase_03 AC 30 ms
6,940 KB
testcase_04 AC 31 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 15 ms
6,940 KB
testcase_08 AC 25 ms
6,944 KB
testcase_09 AC 13 ms
6,944 KB
testcase_10 AC 18 ms
6,944 KB
testcase_11 AC 26 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  long long n,tw,d;
  cin >> n >> tw >> d;
  vector<long long> d0(tw+1,-4e18);
  vector<long long> d1(tw+1,-4e18);
  d0[0]=0;
  d1[0]=0;

  while(n>0){
    n--;
    long long t,w,v;
    cin >> t >> w >> v;
    if(t==0){
      for(long long i=tw-w;i>=0;i--){
        d0[i+w]=max(d0[i+w],d0[i]+v);
      }
    }
    else{
      for(long long i=tw-w;i>=0;i--){
        d1[i+w]=max(d1[i+w],d1[i]+v);
      }
    }
  }

  long long res=0;
  for(long long i=0;i<=tw;i++){
    for(long long j=0;i+j<=tw;j++){
      if(abs(i-j)<=d){
        res=max(res,d0[i]+d1[j]);
      }
    }
  }

  // for(auto &nx : d0){cout << nx << " ";}cout << "\n";
  // for(auto &nx : d1){cout << nx << " ";}cout << "\n";
  cout << res << "\n";
  return 0;
}
0