結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー 沙耶花
提出日時 2023-08-18 21:33:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 3,328 ms
コンパイル使用メモリ 253,176 KB
最終ジャッジ日時 2025-02-16 09:41:19
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

pair<int,mint> get(pair<int,mint> x,pair<int,mint> y){
	if(x.first==y.first){
		x.second += y.second;
		return x;
	}
	if(x.first>y.first)return x;
	return y;
}
pair<int,mint> e(){
	return make_pair(0,0);
}

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<int> c(N),d(N);
	rep(i,N)cin>>c[i];
	rep(i,N)cin>>d[i];
	
	vector<pair<int,mint>> dp(K+1,e());
	dp[0] = make_pair(0,1);
	rep(i,K){
		rep(j,N){
			if(i+c[j]<=K){
				auto v = dp[i];
				v.first += d[j];
				dp[i+c[j]] = get(dp[i+c[j]],v);
			}
		}
	}
	
	pair<int,mint> ans = e();
	//ans.second = 1;
	rep(i,K+1)ans = get(ans,dp[i]);
	cout<<ans.first<<endl<<ans.second.val()<<endl;
		
	return 0;
}
0