Xoring in Base 10
Tag(s):

Algorithms, Medium-Hard, Meet-in-the-middle

Problem
Editorial
Analytics

Given two numbers $A = (A_0A_1...A_n)$ and $B = (B_0B_1..B_n)$ in base $10$, we define the xor of A and B as $A \odot B = (X_0X_1...X_n)$, where $X_i = (A_i + B_i) \mod 10$.

Little Achraf has an array S of integers in base $10$ and he was asked by his professor Toman to find the maximum number he can get by xoring exactly k numbers.

Input format:

First line contains two integers n and k, denoting the number elements in the sequence, and the number of integers you have to xor. Next line contains n integers.

Output format:

Output a single integer denoting the answer of the problem in base $10$.

Constraints:

• $1 \le n \le 40$
• $1 \le k \le n$
• $0 \le S_i \le 10^9$, for all $i \in [1, n]$
SAMPLE INPUT
3 2
4 1 5
SAMPLE OUTPUT
9

Explanation

By choosing numbers 5 and 4, you will get the maximum score.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 1024 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

CODE EDITOR

Initializing Code Editor...