結果

問題 No.974 最後の日までに
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2020-02-16 00:11:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,035 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 60,536 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 03:22:27
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,948 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>

int w;
long long int A[100], B[100], C[100];

struct S {
  long long int money;
  long long int love;
};

std::vector<S> states0[3], states1[3], tmp;

int main(){
  scanf("%d", &w);
  for(int i = 0; i < w; i++) scanf("%lld%lld%lld", A+i, B+i, C+i);

  for(int t = 0; t < 3; t++){
    if(t==2) states1[t].emplace_back(S({0, 0}));
    else states0[t].emplace_back(S({0, 0}));
    for(int i = t ? (w+1)/2: 0; i < (t ? w : (w+1) / 2); i++){
      for(auto it0 = states0[t].begin(), it1 = states1[t].begin(); ;){
        if(it0 == states0[t].end()){ for(; it1 != states1[t].end(); ++it1){ tmp.emplace_back(S({it1->money - C[i], it1->love + B[i]})); } break;}
        else if(it1 == states1[t].end()){ for(; it0 != states0[t].end(); ++it0){ tmp.emplace_back(S({it0->money + A[i], it0->love})); } break;}
        else if(it0->money + A[i] >= it1->money - C[i] && it0->love >= it1->love + B[i]) ++it1;
        else if(it0->money + A[i] <= it1->money - C[i] && it0->love <= it1->love + B[i]) ++it0;
        else if(it0->money + A[i] <= it1->money - C[i]) tmp.emplace_back(S({it0->money + A[i], it0->love})), ++it0;
        else tmp.emplace_back(S({it1->money - C[i], it1->love + B[i]})), ++it1;
      }
      states0[t].swap(states1[t]);
      states0[t].swap(tmp);
      tmp.clear();
    }
  }
// printf("%ld %ld %ld %ld\n", states0[0].size(), states1[0].size(), states0[1].size(), states0[2].size());

  long long int ans = 0;
  for(auto it0 = states0[0].begin(), it1 = states0[1].end(); it0 != states0[0].end(); ++it0){
    while(it1 != states0[1].begin() && it0->money + (it1-1)->money >= 0) --it1;
    if(it1 != states0[1].end())
    ans = std::max(ans, it0->love + it1->love);
  }
  for(auto it0 = states1[0].begin(), it1 = states0[2].end(); it0 != states1[0].end(); ++it0){
    while(it1 != states0[2].begin() && it0->money + (it1-1)->money >= 0) --it1;
    if(it1 != states0[2].end())
    ans = std::max(ans, it0->love + it1->love);
  }

  printf("%lld\n", ans);

  return 0;
}
0