結果

問題 No.2232 Miser's Gift
ユーザー harshith akkapelli
提出日時 2023-03-03 21:55:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 1,932 ms
コンパイル使用メモリ 196,612 KB
最終ジャッジ日時 2025-02-11 02:26:48
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long int ll;
using T_=pair<ll,ll>;


void routine(){
	ll n,w;
	cin >> n >> w;
	vector<pair<ll,ll>> v(n);
	for(ll i = 0;i < n;i++){
		cin >> v[i].f >> v[i].s;
	}
	vector<ll> dp(w+1,0);
	for(ll j = 0;j <n;j++){
		for(ll i = w;i >=0;i--){
			if(i-v[j].f >= 0)dp[i] =max<ll>(dp[i],v[j].s+dp[i-v[j].f]);
		}
	}
	for(ll i = 1;i <= w;i++){
		ll x = dp[w], y = dp[w-i];
		cout << x+1-y << "\n"; 
	}
	return;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t = 1;
	while(t--){
		routine();
	}
	return 0;
}
0