提交时间:2023-12-02 07:57:26
运行 ID: 113251
#include<bits/stdc++.h> #define int long long using namespace std; int dp[3][114514],v[114],w[114],ans; signed main(){ int n,capa; cin>>capa>>n; for (int i = 1;i <= n;i++){ cin>>w[i]>>v[i]; } memset(dp,0x3f,sizeof(dp)); dp[0][0] = 0; for (int i = 1;i <= n;i++){ for (int j = 0;j <= 100000;j++){ if (j >= v[i]){ dp[i & 1][j] = min(dp[(i - 1) & 1][j],dp[(i - 1) & 1][j - v[i]] + w[i]); } else{ dp[i & 1][j] = dp[(i - 1) & 1][j]; } if (dp[i & 1][j] <= capa){ ans = max(ans,j); } } } cout<<ans<<endl; return 0; }