Problem:
Huge Knapsack Problem

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 ≤ 40

1 ≤ vi ≤ 1015

1 ≤ wi ≤ 1015

1 ≤ W ≤ 1015

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: Runtime Error)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long W = long.Parse(str[1]);
        long[] Av = new long[0];
        long[] Aw = new long[0];
        long[] Bv = new long[0];
        long[] Bw = new long[0];
        for(int j=0;j<2;j++){
            int n = j == 0 ? N/2 : N - N/2;
            long[] v = new long[1 << n];
            long[] w = new long[1 << n];
            long[] tv = new long[n];
            long[] tw = new long[n];
            for(int i=0;i<n;i++){
                str = Console.ReadLine().Split(' ');
                tv[i] = int.Parse(str[0]);
                tw[i] = int.Parse(str[1]);
            }
            for(int i=0;i<1 << n;i++){
                long vs = 0;
                long ws = 0;
                for(int k=0;k<20;k++){
                    if((i & (1 << k)) != 0){
                        vs += tv[k];
                        ws += tw[k];
                    }
                }
                v[i] = vs;
                w[i] = ws;
            }
            Array.Sort(w,v);
            List<long> dv = new List<long>();
            List<long> dw = new List<long>(); 
            int vp = 0;
            long lv = v[0] - 1;
            while(vp < v.Length){
                long maxv = v[vp];
                while(vp < v.Length - 1 && w[vp] == w[vp+1]){
                    vp++;
                    maxv = Math.Max(maxv,v[vp]);
                }
                if(lv < maxv){
                    lv = maxv;
                    dv.Add(lv);
                    dw.Add(w[vp]);
                }
                vp++;
            }
            if(j == 0){
                Av = dv.ToArray();
                Aw = dw.ToArray();
            }
            else{
                Bv = dv.ToArray();
                Bw = dw.ToArray();
            }
        }
        {
            int p = Aw.Length-1;
            long max = 0;
            for(int i=0;i<Bw.Length;i++){
                while(p >= 0 && Bw[i]+Aw[p] > W){
                    p--;
                }
                if(p == -1){
                    break;
                }
                else{
                    max = Math.Max(max,Bv[i]+Av[p]);
                }
            }
            sb.Append(max+"\n");
        }
    }
}