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 JAVA (judge verdict: Wrong Answer)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long W = in.nextLong();
			long[] v1 = new long[n/2];
			long[] w1 = new long[n/2];
			long[] v2 = new long[n-n/2];
			long[] w2 = new long[n-n/2];

			for (int i = 0; i < n/2; i++) {
				v1[i] = in.nextLong();
				w1[i] = in.nextLong();
			}
			for (int i = 0; i < n-n/2; i++) {
				v2[i] = in.nextLong();
				w2[i] = in.nextLong();
			}


			Map<Long, Long> map1 = new TreeMap<>();

			for (int i = 0; i < (1<<n/2); i++) {
				long wtmp = 0, vtmp = 0;
				for (int j = 0; j < n/2; j++) {
					if ((i >> j & 1) == 1) {
						vtmp += v1[j];
						wtmp += w1[j];
					}
				}
				if (wtmp <= W) {
					map1.put(vtmp, wtmp);
				}
			}

			Map<Long, Long> map2 = new TreeMap<>();

			for (int i = 0; i < (1<<(n-n/2)); i++) {
				long wtmp = 0, vtmp = 0;
				for (int j = 0; j < n-n/2; j++) {
					if ((i >> j & 1) == 1) {
						vtmp += v2[j];
						wtmp += w2[j];
					}
				}
				if (wtmp <= W) {
					map2.put(vtmp, wtmp);
				}
			}

			long ans = 0;
			for (Entry<Long, Long> e1 : map1.entrySet()) {
				for (Entry<Long, Long> e2 : map2.entrySet()) {
					if (e1.getValue()+e2.getValue() <= W) {
						ans = Math.max(ans, e1.getKey()+e2.getKey());
					}
				}
			}


			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}