codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1210B.md (2389B)


      1 Source: https://codeforces.com/problemset/problem/1210/B
      2 
      3 B. Marcin and Training Camp
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Marcin is a coach in his university. There are $n$ students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.
     22 
     23 Let's focus on the students. They are indexed with integers from $1$ to $n$. Each of them can be described with two integers $a_i$ and $b_i$; $b_i$ is equal to the skill level of the $i$-th student (the higher, the better). Also, there are $60$ known algorithms, which are numbered with integers from $0$ to $59$. If the $i$-th student knows the $j$-th algorithm, then the $j$-th bit ($2^j$) is set in the binary representation of $a_i$. Otherwise, this bit is not set.
     24 
     25 Student $x$ thinks that he is better than student $y$ if and only if $x$ knows some algorithm which $y$ doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.
     26 
     27 Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?
     28 
     29 Input
     30 
     31 The first line contains one integer $n$ ($1 \leq n \leq 7000$) — the number of students interested in the camp.
     32 
     33 The second line contains $n$ integers. The $i$-th of them is $a_i$ ($0 \leq a_i \lt 2^{60}$).
     34 
     35 The third line contains $n$ integers. The $i$-th of them is $b_i$ ($1 \leq b_i \leq 10^9$).
     36 
     37 Output
     38 
     39 Output one integer which denotes the maximum sum of $b_i$ over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 4
     47 3 2 3 6
     48 2 8 5 10
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 15
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 3
     61 1 2 3
     62 1 2 3
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 0
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 1
     75 0
     76 1
     77 ```
     78 
     79 Output
     80 
     81 ```
     82 0
     83 ```
     84 
     85 Note
     86 
     87 In the first sample test, it's optimal to send the first, the second and the third student to the camp. It's also possible to send only the first and the third student, but they'd have a lower sum of $b_i$.
     88 
     89 In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset.