結果
| 問題 | No.783 門松計画 | 
| コンテスト | |
| ユーザー |  koyopro | 
| 提出日時 | 2020-01-03 16:44:20 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 37 ms / 2,000 ms | 
| コード長 | 1,780 bytes | 
| コンパイル時間 | 1,374 ms | 
| コンパイル使用メモリ | 161,728 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-23 12:23:11 | 
| 合計ジャッジ時間 | 2,305 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
int dxy[] = {0, 1, 0, -1, 0};
/*================================*/
int N,C;
struct Bamboo {
    int l, w;
};
bool is_kadomatsu(int a, int b, int c) {
    if (a==b || b==c || c==a) return false;
    if (!(b < a && b < c) && !(b > a && b > c)) return false;
    return true;
}
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin>>N>>C;
    
    int L = 50;
    
    vector<Bamboo> B(N);
    REP(i,N) cin >> B[i].l;
    REP(i,N) cin >> B[i].w;
    
    // 2つ前長さ, 1つ前長さ, 所持金 => 累計長さ
    int DP[L+1][L+1][C+1];
    REP(i,L+1)REP(j,L+1)REP(k,C+1)DP[i][j][k]=-1;
    
    DP[0][0][C] = 0;
    
    int ans = 0;
    RREP(k,C+1) REP(i,L+1) REP(j,L+1) {
        if (j == 0 && i != 0) continue; // 2つ前が未定なら一つ前も未定である必要がある
        if (DP[i][j][k] < 0) continue;
        for (auto b : B) {
            if (k < b.w) continue; // 残高不足
            if (i!=0 && j!=0 && !is_kadomatsu(i, j, b.l)) continue;
            int ret = DP[j][b.l][k-b.w] = max(DP[j][b.l][k-b.w], DP[i][j][k] + b.l);
            if(i!=0 && j!=0) ans = max(ans, ret);
        }
    }
    
     cout << ans << endl;
    
    return 0;
}
            
            
            
        