Problem:
0-1 Knapsack Problem II

You have N items that you want to put them into a knapsack. Item i has value vi and weight wi.

You want to find a subset of items to put such that:

The total value of the items is as large as possible.

The items have combined weight at most W, that is capacity of the knapsack.

Find the maximum total value of items in the knapsack.

Input

N W
v1 w1
v2 w2
:
vN wN

The first line consists of the integers N and W. In the following N lines, the value and weight of the i-th item are given.

Output

Print the maximum total values of the items in a line.

Constraints

1 ≤ N ≤ 100

1 ≤ vi ≤ 100

1 ≤ wi ≤ 10,000,000

1 ≤ W ≤ 1,000,000,000

Sample Input 1

4 5
4 2
5 2
2 1
8 3

Sample Output 1

13

Sample Input 2

2 20
5 9
4 10

Sample Output 2

9

Solution in C# (judge verdict: Accepted)

#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var NM = Console.ReadLine().SplittedStringToInt32List();
        var N = NM[0];
        var M = NM[1];
        var an = new List<KeyValuePair<int, int>>();
        var dp = new int[N+1,10010];
        for (int i = 0; i < N; i++)
        {
            var vw = Console.ReadLine().SplittedStringToInt32List();
            an.Add(new KeyValuePair<int, int>( vw[0], vw[1]));
        }
        for (int i = 0; i < N+1; i++)
        {
            for (int j = 0; j < 10010; j++)
            {
                dp[i, j] = INF;
            }
        }
        dp[0, 0] = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 10010; j++)
            {
                if (j - an[i].Key >= 0)
                    dp[i + 1, j] = Math.Min(dp[i, j], dp[i, j - an[i].Key] + an[i].Value);
                else
                    dp[i + 1, j] = dp[i, j];
            }
        }
        var max = -1;
        for (int i = 0; i < 10010; i++)
        {
            var num = dp[N, i];
            if (num <= M)
                max = i;
        }
        Console.WriteLine(max);

        Console.ReadLine();
    }
    

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    #endregion
}