L. Looking for Taste

Codeforces
IDCF10199L
Time3000ms
Memory1024MB
Difficulty
English · Original
Formal · Original
Fouad went to a restaurant and while reading the menu, he found out that it includes an interesting piece of information about each meal. This piece of information was the tastes each meal contains. The menu contains N meals such that each meal is represented by an integer Ai where the jth bit in the binary representation of Ai represents the availability of taste j in this meal (1 means you will feel the taste while eating it and 0 means you will not). You will feel taste j if you eat some meals, such that any of them has the bit j equals to 1. In other words, the tastes included by eating meals Ai and Aj are the tastes included by the number , where is the bitwise OR operation. Fouad wants to eat many meals so that he can enjoy the food as maximum as possible, but he cannot eat more than K meals (because of his strict diet). Since not all the tastes are the same, he is asking for your help to select a subset of K meals, such that the number representing the overall food is as maximum as possible (the bitwise OR of the chosen meals is as maximum as possible). The first line of the input consists of a single integer T, the number of test cases. Each test case starts with a line containing two space-separated integers N, K (where 20 ≤ K ≤ N ≤ 105). The second line of the test case contains N space-separated integers A1, ..., AN (where for all i we have 0 ≤ Ai ≤ 106). For each test case, print a single line containing a single integer X representing the maximum value of tastes Fouad can feel by eating a subset of at most K meals. If the subset of meals Fouad will eat will contain the ith taste, then the ith bit of the number X must be 1, otherwise, the ith bit must be 0. In the sample, he can eat all the meals, so the result is bitwise OR of all the given numbers. ## Input The first line of the input consists of a single integer T, the number of test cases.Each test case starts with a line containing two space-separated integers N, K (where 20 ≤ K ≤ N ≤ 105).The second line of the test case contains N space-separated integers A1, ..., AN (where for all i we have 0 ≤ Ai ≤ 106). ## Output For each test case, print a single line containing a single integer X representing the maximum value of tastes Fouad can feel by eating a subset of at most K meals. If the subset of meals Fouad will eat will contain the ith taste, then the ith bit of the number X must be 1, otherwise, the ith bit must be 0. [samples] ## Note In the sample, he can eat all the meals, so the result is bitwise OR of all the given numbers.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case, let $ Q \in \mathbb{Z} $ be the number of operations, and let $ X = (x_1, x_2, \dots, x_Q) $ be a sequence of integers representing the queries. **Constraints** 1. $ 1 \le T \le \text{unspecified} $ 2. For each test case: - $ 1 \le Q \le 10^5 $ - $ 0 \le x_i \le 10^5 $ for all $ i \in \{1, \dots, Q\} $ **Objective** For each query $ x_i $, output $ y_i $ such that $ y_i = x_i $, under the constraint that the line is defined by $ x = y $. $$ y_i = x_i \quad \text{for all } i \in \{1, \dots, Q\} $$
API Response (JSON)
{
  "problem": {
    "name": "L. Looking for Taste",
    "description": {
      "content": "Fouad went to a restaurant and while reading the menu, he found out that it includes an interesting piece of information about each meal. This piece of information was the tastes each meal contains. ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 1048576
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10199L"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Fouad went to a restaurant and while reading the menu, he found out that it includes an interesting piece of information about each meal. This piece of information was the tastes each meal contains.\n\n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case, let $ Q \\in \\mathbb{Z} $ be the number of operations, and let $ X = (x_1, x_2, \\dots, x_Q) $ be a sequence...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments