/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 16ms 3.113 MiB
#2 Accepted 68ms 3.277 MiB
#3 Accepted 68ms 3.266 MiB
#4 Accepted 70ms 3.266 MiB
#5 Accepted 67ms 3.281 MiB
#6 Accepted 67ms 3.301 MiB
#7 Wrong Answer 71ms 3.297 MiB
#8 Wrong Answer 20ms 2.941 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-11-11 03:16:06
Judged By
Score
30
Total Time
71ms
Peak Memory
3.301 MiB