Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <assert.h>
- #include <inttypes.h>
- typedef unsigned int uint_t;
- const uint_t N = 1000000, LK = 30, B = 100000000;
- static uint_t read_uint()
- {
- const uint_t D = 10;
- uint_t u = 0;
- do {
- int c = getchar_unlocked();
- assert (0 <= c);
- u = c - '0';
- } while (D <= u);
- for (;;) {
- uint_t v = getchar_unlocked() - '0';
- if (D <= v)
- break;
- u = u * D + v;
- }
- return u;
- }
- int main()
- {
- uint_t ms[LK];
- uint64_t ss[LK];
- uint_t n = read_uint();
- assert (0 < n && n <= N);
- uint_t k = read_uint();
- assert ((k >> LK) == 0);
- uint_t m = 0;
- ms[m++] = k;
- {
- uint_t j = 0;
- while (k & (1U << j))
- j++;
- for (; j < LK; j++) {
- uint_t jm = (1U << j);
- if ((k & jm) == 0)
- continue;
- uint_t k1 = (k & ~(jm)) | (jm - 1);
- //fprintf(stderr, "adding k1=%u\n", k1);
- ms[m++] = k1;
- }
- }
- for (uint_t i = 0; i < m; i++)
- ss[i] = 0;
- for (uint_t i = 0; i < n; i++) {
- uint_t a = read_uint();
- assert ((a >> LK) == 0);
- uint_t b = read_uint();
- assert (0 < b && b <= B);
- //fprintf(stderr, "checking pair (%u, %u) \n", a, b);
- for (uint_t j = 0; j < m; j++) {
- if ((~ms[j] & a) == 0) {
- ss[j] += b;
- //fprintf(stderr, "it passed m=%u\n", ms[j]);
- }
- }
- }
- uint64_t res = ss[0];
- for (uint_t i = 1; i < m; i++) {
- if (res < ss[i])
- res = ss[i];
- }
- printf("%" PRIu64 "\n", res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement