Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <fstream>
- #include <array>
- using namespace std;
- typedef long long ll;
- vector<int> palindromes;
- int n, weight_max;
- int w[105], v[105];
- ll dp[105][100005];
- int main()
- {
- cin >> n >> weight_max;
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> w[i] >> v[i];
- sum += v[i];
- }
- for(int i = 0; i <= n; i++) {
- for(int j = 0; j <= sum; j++) {
- dp[i][j] = 2e9;
- }
- }
- dp[0][0] = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j <= sum; j++) {
- dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
- if(j + v[i] <= sum) {
- dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
- }
- }
- }
- for(int i = sum; i >= 0; i--) {
- if(dp[n][i] <= weight_max) {
- cout << i << endl;
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement