Submission #3428078

Source Code Expand

Copy
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.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;

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 long LINF = 1L << 55;
	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 k = in.nextLong();
			long[] a = new long[n], b = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextLong();
				b[i] = in.nextLong();
			}

			List<Long> list = new ArrayList<>();
			list.add(k);
			for (int i = 30; i >= 0; i--) {
				if ((k >> i & 1) == 1) {
					long tmp = k;
					tmp -= 1 << i;
					tmp |= (1 << i) - 1;
					list.add(tmp);
				}
			}

			long ans = 0;
			for (long mask : list) {
				long tmp = 0;
				for (int i = 0; i < n; i++) {
					if ((a[i] | mask) == mask) {
						tmp += b[i];
					}
				}
				ans = Math.max(ans, tmp);
			}
			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 int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = 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 long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

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

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

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

}

Submission Info

Submission Time
Task D - IntegerotS
User tutuz
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 3581 Byte
Status
Exec Time 353 ms
Memory 44500 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 500 / 500 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 243 ms 43032 KB
02.txt 240 ms 40028 KB
03.txt 244 ms 42216 KB
04.txt 230 ms 38832 KB
05.txt 228 ms 44364 KB
06.txt 234 ms 37500 KB
07.txt 230 ms 41116 KB
08.txt 248 ms 43196 KB
09.txt 230 ms 40160 KB
10.txt 244 ms 41344 KB
11.txt 236 ms 41008 KB
12.txt 241 ms 43464 KB
13.txt 243 ms 41672 KB
14.txt 241 ms 38204 KB
15.txt 236 ms 40380 KB
16.txt 242 ms 43264 KB
17.txt 246 ms 38936 KB
18.txt 236 ms 41264 KB
19.txt 245 ms 44500 KB
20.txt 254 ms 40604 KB
21.txt 237 ms 42304 KB
22.txt 237 ms 40344 KB
23.txt 237 ms 42480 KB
24.txt 229 ms 42336 KB
25.txt 258 ms 40852 KB
26.txt 238 ms 42112 KB
27.txt 237 ms 42536 KB
28.txt 239 ms 38840 KB
29.txt 246 ms 36916 KB
30.txt 242 ms 40112 KB
31.txt 245 ms 39648 KB
32.txt 254 ms 37716 KB
33.txt 221 ms 40712 KB
34.txt 242 ms 40664 KB
35.txt 246 ms 42236 KB
36.txt 224 ms 39268 KB
37.txt 225 ms 41652 KB
38.txt 233 ms 39384 KB
39.txt 239 ms 42284 KB
40.txt 238 ms 42192 KB
41.txt 353 ms 38300 KB
42.txt 236 ms 42632 KB
43.txt 237 ms 42516 KB
44.txt 229 ms 42564 KB
45.txt 232 ms 43076 KB
46.txt 255 ms 41132 KB
47.txt 243 ms 40472 KB
48.txt 251 ms 39192 KB
49.txt 225 ms 42692 KB
50.txt 209 ms 40100 KB
51.txt 73 ms 17876 KB
52.txt 73 ms 18260 KB
53.txt 74 ms 20820 KB
54.txt 75 ms 20948 KB
55.txt 72 ms 17876 KB
56.txt 72 ms 19668 KB
57.txt 75 ms 20688 KB
58.txt 74 ms 18900 KB
59.txt 75 ms 23380 KB
60.txt 75 ms 20436 KB
s1.txt 75 ms 20820 KB
s2.txt 73 ms 21460 KB
s3.txt 73 ms 19664 KB