/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 15ms 2.906 MiB
#2 Accepted 68ms 3.266 MiB
#3 Accepted 69ms 3.273 MiB
#4 Accepted 69ms 3.262 MiB
#5 Accepted 68ms 3.266 MiB
#6 Accepted 68ms 3.297 MiB
#7 Wrong Answer 71ms 3.297 MiB
#8 Wrong Answer 19ms 3.004 MiB
#9 Wrong Answer 17ms 3.129 MiB
#10 Wrong Answer 64ms 3.512 MiB
#11 Wrong Answer 17ms 3.129 MiB
#12 Wrong Answer 34ms 3.223 MiB
#13 Wrong Answer 79ms 3.172 MiB
#14 Wrong Answer 67ms 3.191 MiB
#15 Wrong Answer 62ms 3.301 MiB

Code

def concatenate_and_maximize(A, N, K):
    A = list(map(str, A))  # Convert to strings for concatenation

    for _ in range(K):
        max_value = ''
        best_index = -1

        # Find the best adjacent pair to concatenate
        for i in range(len(A) - 1):
            new_value = A[i] + A[i + 1]
            if new_value > max_value:
                max_value = new_value
                best_index = i

        if best_index == -1:
            break
        
        # Perform the concatenation
        A[best_index] = max_value
        del A[best_index + 1]  # Remove the second part of the concatenated pair

    # After all operations, find and return the maximum value in the array
    return max(A)

# Reading input
T = int(input())
for _ in range(T):
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    print(concatenate_and_maximize(A, N, K))

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
Python 3 (Python 3.12.3)
Submit At
2024-08-16 16:06:40
Judged At
2024-10-03 13:28:39
Judged By
Score
30
Total Time
79ms
Peak Memory
3.512 MiB