結果

問題 No.974 最後の日までに
ユーザー utouto97utouto97
提出日時 2020-01-21 22:13:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 166,824 KB
実行使用メモリ 15,508 KB
最終ジャッジ日時 2024-04-14 22:00:27
合計ジャッジ時間 7,433 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
13,648 KB
testcase_01 AC 105 ms
13,956 KB
testcase_02 AC 103 ms
13,780 KB
testcase_03 AC 106 ms
13,892 KB
testcase_04 AC 107 ms
13,932 KB
testcase_05 AC 105 ms
13,648 KB
testcase_06 AC 105 ms
13,860 KB
testcase_07 AC 107 ms
14,096 KB
testcase_08 AC 105 ms
13,652 KB
testcase_09 AC 108 ms
14,376 KB
testcase_10 AC 109 ms
13,832 KB
testcase_11 AC 108 ms
13,520 KB
testcase_12 AC 109 ms
13,648 KB
testcase_13 AC 109 ms
13,520 KB
testcase_14 AC 108 ms
13,652 KB
testcase_15 AC 108 ms
13,872 KB
testcase_16 AC 110 ms
14,020 KB
testcase_17 AC 127 ms
13,848 KB
testcase_18 AC 128 ms
14,052 KB
testcase_19 AC 128 ms
13,772 KB
testcase_20 AC 125 ms
13,648 KB
testcase_21 AC 124 ms
13,776 KB
testcase_22 AC 125 ms
15,328 KB
testcase_23 AC 126 ms
13,780 KB
testcase_24 AC 127 ms
15,032 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 90 ms
12,732 KB
testcase_28 AC 111 ms
14,452 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 125 ms
15,508 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 71 ms
10,376 KB
testcase_34 AC 115 ms
13,776 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 126 ms
13,976 KB
testcase_38 AC 1 ms
6,944 KB
testcase_39 AC 1 ms
6,940 KB
testcase_40 AC 79 ms
12,348 KB
testcase_41 AC 98 ms
13,776 KB
testcase_42 AC 126 ms
13,916 KB
testcase_43 AC 128 ms
13,648 KB
testcase_44 AC 101 ms
12,348 KB
testcase_45 AC 78 ms
9,732 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

int w, a[55], b[55], c[55];

void dfs(int i, int n, int money, int like, vector<P> &v){
  if(i == n){
    v.emplace_back(money, like);
    return;
  }

  dfs(i+1, n, money+a[i], like, v);
  if(i+1 < n) dfs(i+2, n, money-c[i+1], like+b[i+1], v);
}

int solve(int half){
  vector<P> x, y;
  dfs(0, half, 0, 0, x);
  dfs(half, w, 0, 0, y);

  sort(all(x)); sort(all(y));

  int ma = -1e15;
  for(auto i = x.rbegin(); i != x.rend(); i++){
    chmax(ma, i->second);
    chmax(i->second, ma);
  }

  int ans = 0;
  for(auto i : y){
    auto j = lower_bound(all(x), P(-i.first, 0LL));
    if(j == x.end()) continue;
    chmax(ans, j->second + i.second);
  }

  return ans;
}

signed main() {
  cin >> w;
  rep(i, 0, w) cin >> a[i] >> b[i] >> c[i];

  cout << max(solve(w/2), solve(w/2+1)) << endl;

  return 0;
}
0