結果
| 問題 | 
                            No.2701 A cans -> B cans
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Rubikun
                         | 
                    
| 提出日時 | 2024-03-29 21:26:37 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 266 ms / 1,000 ms | 
| コード長 | 1,187 bytes | 
| コンパイル時間 | 2,369 ms | 
| コンパイル使用メモリ | 193,748 KB | 
| 最終ジャッジ日時 | 2025-02-20 14:45:51 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 73 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=5005;
const ll INF=1LL<<60;
ll dp[MAX*2][MAX];
int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,M;cin>>N>>M;
    for(int i=0;i<MAX*2;i++) for(int j=0;j<MAX;j++) dp[i][j]=-INF;
    dp[0][0]=0;
    
    for(int i=0;i<N;i++){
        ll a,b,c;cin>>a>>b>>c;
        for(int j=0;j<=M;j++){
            chmax(dp[2*(i+1)][j],dp[2*i][j]);
            if(j+a<=M) chmax(dp[2*i+1][j+a],dp[2*i][j]+b*c);
        }
        for(int j=a-b;j<=M;j++){
            chmax(dp[2*i+1][j],dp[2*i+1][j-(a-b)]+b*c);
        }
        for(int j=0;j<=M;j++) chmax(dp[2*(i+1)][j],dp[2*i+1][j]);
    }
    
    ll ma=0;
    for(int j=1;j<=M;j++){
        chmax(ma,dp[2*N][j]);
        cout<<ma<<"\n";
    }
}
            
            
            
        
            
Rubikun