115462024-10-26 11:27:31balintBob Baba Zárójelsorozatapython3Wrong answer 20/10017ms3344 KiB
def main() -> None:
    N = int(input())
    nums = list(map(int, input().strip().split()))

    summa = sum(nums)
    
    if summa % 2 != 0: # nem lehetséges
        return -1
        
    nums.sort(reverse=True)
    brackets = [nums[0]*"("]


    i = 1
    while i < N:
        for j in range(1,N-i+1):
            i_j = sum(nums[i:j+i])
            if nums[i] == i_j:
                brackets.append(i_j * ")")
                i += j+1
                break
        if i < N:
            brackets.append(nums[i]*"(")
            i+=1
    if len(brackets) < N:
        brackets.append(nums[-1]*")")
       # brackets.append(nums[i]*("(" if sum(nums[i:]) %2 ==0 else ")"))

    return "".join(brackets)
print(main())
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted16ms3312 KiB
2Accepted17ms3136 KiB
3Accepted17ms2940 KiB
subtask220/20
4Accepted16ms3320 KiB
5Accepted16ms3140 KiB
6Accepted16ms3140 KiB
subtask30/30
7Wrong answer16ms3268 KiB
8Wrong answer16ms3160 KiB
9Wrong answer14ms3140 KiB
10Accepted16ms3140 KiB
11Wrong answer16ms2936 KiB
subtask40/50
12Accepted17ms3128 KiB
13Wrong answer17ms3208 KiB
14Wrong answer17ms3140 KiB
15Wrong answer17ms3324 KiB
16Accepted16ms3156 KiB
17Accepted17ms3084 KiB
18Accepted16ms3140 KiB
19Wrong answer16ms3296 KiB
20Wrong answer17ms3140 KiB
21Wrong answer17ms3064 KiB
22Accepted16ms3344 KiB
23Accepted16ms3140 KiB
24Accepted17ms3140 KiB
25Wrong answer17ms3140 KiB
26Wrong answer17ms3152 KiB
27Accepted16ms3140 KiB
28Accepted17ms3128 KiB
29Accepted16ms3144 KiB
30Accepted17ms3168 KiB
31Wrong answer16ms3176 KiB
32Wrong answer17ms3272 KiB
33Accepted17ms3012 KiB
34Accepted17ms3140 KiB
35Accepted17ms3096 KiB
36Wrong answer17ms3148 KiB
37Wrong answer17ms3140 KiB
38Wrong answer17ms3144 KiB
39Wrong answer17ms3140 KiB
40Wrong answer17ms3148 KiB
41Wrong answer17ms3140 KiB
42Wrong answer17ms3140 KiB
43Wrong answer16ms3108 KiB
44Wrong answer17ms3084 KiB
45Wrong answer16ms3140 KiB
46Wrong answer16ms3236 KiB
47Wrong answer16ms3228 KiB
48Wrong answer17ms3140 KiB
49Wrong answer17ms3324 KiB
50Wrong answer17ms3144 KiB
51Wrong answer17ms3256 KiB
52Wrong answer17ms3144 KiB
53Wrong answer17ms3140 KiB
54Wrong answer16ms3264 KiB
55Wrong answer16ms3140 KiB
56Wrong answer17ms3084 KiB
57Wrong answer16ms3280 KiB
58Wrong answer17ms3132 KiB