TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N,K = na()
que = na()
revque = que[::-1]

ans = 0
for a in range(min(N,K)+1):
    for b in range(min(K-a,N-a)+1):
        sum_q = que[:a] + revque[:b] if b>0 else que[:a]
        r = sum(sum_q)
        sum_q.sort()
        l = 0
        #print(sum_q)
        if sum_q:
            for i in range(min(K-(a+b),len(sum_q))):
                #sprint(i)
                if sum_q[i]>0:
                    l = i
                    break
        r = sum(sum_q[l:])
        if ans < r:
            ans = r
print(ans)

import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N,K = na()
que = na()
revque = que[::-1]

ans = 0
for a in range(min(N,K)+1):
    for b in range(min(K-a,N-a)+1):
        sum_q = que[:a] + revque[:b] if b>0 else que[:a]
        r = sum(sum_q)
        sum_q.sort()
        l = 0
        #print(sum_q)
        if sum_q:
            for i in range(min(K-(a+b),len(sum_q))):
                #print(i)
                if sum_q[i]>0:
                    l = i
                    break
                else:
                    r-=sum_q[i]
        if ans < r:
            ans = r
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
n,k=map(int,input().split())
v=[int(i) for i in input().split()]
ans=[]

for i in range(min(n,k)+1):
    for j in range(min(n,k)-i+1):
        d=k-i-j
        l=v[0:i]
        r=v[n-j:n]
        p=r+l
        q=[]
        s=sum(p)
        for x in p:
            if x<0:
                q.append(x)
        q.sort()
        for x in range(d):
            s-=q[x]
        ans.append(s)
        
print(max(ans))






n,k=map(int,input().split())
v=[int(i) for i in input().split()]
ans=[]

for i in range(min(n,k)+1):
    for j in range(min(n,k)-i+1):
        d=k-i-j
        l=v[0:i]
        r=v[n-j:n]
        p=r+l
        q=[]
        s=sum(p)
        for x in p:
            if x<0:
                q.append(x)
        q.sort()
        for x in range(min(len(q),d)):
            s-=q[x]
        ans.append(s)
        
print(max(ans))






Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
from collections import deque

n,k = map(int,input().split())
D =map(int,input().split())
ans = 0

for toridasukaisu in range(min(k,n)+1):
    for i in range(toridasukaisu+1):
        value = []
        l = i
        r = toridasukaisu - i
        for j in range(l):
            value.append(D[j])
        for j in range(r):
            value.append(D[-1-j])

        value.sort()
        suterukazu = 0
        suterukaisu = k - toridasukaisu
        for e in value:
            if suterukazu >= suterukaisu:
                break
            if e < 0:
                suterukazu += 1
            
        ans = max(sum(value[suterukazu:]),ans)
        
print(ans)               


            


    




from collections import deque

n,k = map(int,input().split())
D =list(map(int,input().split()))
ans = 0

for toridasukaisu in range(min(k,n)+1):
    for i in range(toridasukaisu+1):
        value = []
        l = i
        r = toridasukaisu - i
        for j in range(l):
            value.append(D[j])
        for j in range(r):
            value.append(D[-1-j])

        value.sort()
        suterukazu = 0
        suterukaisu = k - toridasukaisu
        for e in value:
            if suterukazu >= suterukaisu:
                break
            if e < 0:
                suterukazu += 1
            
        ans = max(sum(value[suterukazu:]),ans)
        
print(ans)               


            


    




Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
def main():
    N, K = map(int, input().split())
    V = [int(v) for v in input().split()]

    m = 0

    r = min(N, K)
    for a in range(r+1):
        for b in range(r+1-a):
            if b == 0:
                v = V[:a]
            else:
                v = V[:a] + V[-b:]
            v.sort()    
            for i in range(K-a-b):
                if v[i] >= 0:
                    break
            s = sum(v[i:])
            if s > m:
                m = s

    print(m)


main()


def main():
    N, K = map(int, input().split())
    V = [int(v) for v in input().split()]

    m = 0 
    r = min(N, K)
    for a in range(r+1):
        for b in range(r+1-a):
            if b == 0:
                v = V[:a]
            else:
                v = V[:a] + V[-b:]
            v.sort()    
            for i in range(K+1-a-b):
                if i >= len(v):
                    break
                if  v[i] >= 0:
                    break
            s = sum(v[i:])
            if s > m:
                m = s

    print(m)


main()


Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):

N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M):
    for j in range(M-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k > len(dump_num):
                break;
            if dump_num[k] >= 1:
                break;
            num -=dump_num[k]
        
        if num > ans:
            ans = num
print(ans)
            


N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M+1):
    for j in range(M+1-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        print(dump_num)
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 0:
                break;
            num -= dump_num[k]
        
        if num >= ans:
            ans = num
print(ans)
            


N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M+1):
    for j in range(M+1-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 0:
                break;
            num -= dump_num[k]
        
        if num >= ans:
            ans = num
print(ans)
            

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N, K = map( int, input().split() )
V = list( map( int, input().split() ) )
 
max_number = 0
for A in range( K ):
  for B in range( K ):
    J = K - A - B
    if J < 0:
      continue
    if A + B >= N:
      hand = V
    else:
      hand = sorted( set( V[ : A ] + V[ N - B : ] ))
    max_number = max( max_number, sum( hand[ J + 1 : ] ))
print( max_number )

N, K = map( int, input().split() )
V = list( map( int, input().split() ) )

max_number = 0
for A in range( K ):
  for B in range( K ):
    J = K - A - B
    if J < 0:
      continue
    hand = sorted( V[ : A ] + V[ N - B : ] )
    max_number = max( max_number, sum( hand[ J : ] ))
    print( 'A:' , A, 'B:' , B, 'K:' , J, 'hand:' , hand, hand[ J : ] )
      
      
print( max_number )

N, K = map( int, input().split() )
V = list( map( int, input().split() ) )
 
max_number = 0
for A in range( K + 1 ):
  for B in range( K + 1 ):
    J = K - A - B
    if J < 0:
      continue
    if A + B >= N:
      hand = V
    else:
      hand = V[ : A ] + V[ N - B : ]
    hand = sorted( hand )
      
    hand_num = 0
    for i, j in enumerate(hand):
      if ( j > 0 ) or ( i == J ):
        hand = hand[ i: ]
        break
    max_number = max( max_number, sum( hand ))
print( max_number )

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
from collections import deque
import heapq

N, K=map(int, input().split())
V=list(map(int, input().split()))
lim=min(N, K)
ans=0
for num in range(lim+1):
    for A in range(num+1):
        B=num-A
        d=deque(V)
        hands=[]
        while d and len(h)<A:
            hands.append(d.popleft())
        while d and len(h)<A+B:
            hands.append(d.pop())
        heapq.heapify(hands)
        cnt=K-num
        while len(hands) and hands[0]<0 and cnt>0:
            cnt-=1
            heapq.heappop(hands)
        ans=max(ans, sum(hands))
print(ans)

from collections import deque
import heapq

N, K=map(int, input().split())
V=list(map(int, input().split()))
lim=min(N, K)
ans=0
for num in range(lim+1):
    for A in range(num+1):
        B=num-A
        d=deque(V)
        hands=[]
        while d and len(hands)<A:
            hands.append(d.popleft())
        while d and len(hands)<A+B:
            hands.append(d.pop())
        heapq.heapify(hands)
        cnt=K-num
        while len(hands) and hands[0]<0 and cnt>0:
            cnt-=1
            heapq.heappop(hands)
        ans=max(ans, sum(hands))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
def abc128_d():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0

    for a in range(max(1, k+1)):  
        for b in range(max(1, k-a+1)):  
            arr = []
            if a > 0: arr += v[:a]
            if b > 0: arr += v[-b:]
            arr.sort()
            for j in range(max(1, a+b)):  
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                print(a, b, j, score, arr)
    print(ans)

if __name__ == '__main__':
    abc128_d()

def abc128_d():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    ans = 0

    for a in range(max(1, k+1)):  
        for b in range(max(1, k-a+1)):  
            if a+b > n: break
            arr = []
            if a > 0: arr += v[:a]
            if b > 0 and a < n: arr += v[max(a, 0, n-b):]
            arr.sort()
            for j in range(max(1, a+b)):  
                if a+b+j > k: break
                score = sum(arr[j:])
                ans = max(ans, score)
                #print(a, b, j, score, arr)
    print(ans)

if __name__ == '__main__':
    abc128_d()

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0

for l in range(k + 1):
	for r in range(k - l + 1):
		hand = []
        if l + r > n:
          break
		
		hand = v[: l]
        
		hand.extend(v[n - r:])
        
		hand_sum = sum(hand)  
		hand.sort()
        
		for i in range(min(k - l - r, l + r)):
			if hand[i] < 0:
			  hand_sum -= hand[i]
		ans = max(ans, hand_sum)

print(ans)

n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0

for l in range(k + 1):
	for r in range(k - l + 1):
		hand = []
		
		hand = v[: l]
        
		hand.extend(v[n - r:])
        
		hand_sum = sum(hand)  
		hand.sort()
        
		for i in range(min(hand.sort())):
			if hand[i] < 0:
			  hand_sum -= hand[i]
		ans = max(ans, hand_sum)

print(ans)

n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0

for l in range(k + 1):
	for r in range(k - l + 1):
		hand = []
		if l + r > n:
			break
        
		hand = v[: l]
        
		hand.extend(v[n - r:])
        
		hand_sum = sum(hand)  
		hand.sort()
        
		for i in range(min(k - l - r, l + r)):
			if hand[i] < 0:
			  hand_sum -= hand[i]
		ans = max(ans, hand_sum)

print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
def v_and_num(queue):
  output = [(0,0)]
  for i in range(len(queue)+1):
    hand = queue[:i]
    hand = sorted(hand)
    for j in range(len(hand)):
      output.append((i+j,sum(hand[j:])))
      if hand[j] > 0:
        break
  return output


n,k = list(map(int,input().split(" ")))
D =   list(map(int,input().split(" ")))

"""
left = D[:n//2+1]
right = list(reversed(D[n//2+1:]))

l = v_and_num(left)
r = v_and_num(right)
M = 0
for k1, v1 in l:
  for k2, v2 in r:
    if k1+k2 > k:
      continue
    if v1+v2 > M:
      M = v1+v2
      """

r = min(k,n)
M = 0
for a in range(r+1):
  for b in range(r+1-a):
    hand = D[:a] + D[-b:] if b!=0 else D[:a]
    print(hand)
    hand = list(sorted(hand))
    i = 0
    for i in range(min(k-a-b+1,a+b)):
      if hand[i] > 0:
        break
    buf = sum(hand[i:])
    if buf > M:
      M = buf
print(M)


def v_and_num(queue):
  output = [(0,0)]
  for i in range(len(queue)+1):
    hand = queue[:i]
    hand = sorted(hand)
    for j in range(len(hand)):
      output.append((i+j,sum(hand[j:])))
      if hand[j] > 0:
        break
  return output


n,k = list(map(int,input().split(" ")))
D =   list(map(int,input().split(" ")))

"""
left = D[:n//2+1]
right = list(reversed(D[n//2+1:]))

l = v_and_num(left)
r = v_and_num(right)
M = 0
for k1, v1 in l:
  for k2, v2 in r:
    if k1+k2 > k:
      continue
    if v1+v2 > M:
      M = v1+v2
      """

r = min(k,n)
M = 0
for a in range(r+1):
  for b in range(r+1-a):
    hand = D[:a] + D[-b:] if b!=0 else D[:a]
    hand = list(sorted(hand))
    i = 0
    for i in range(min(k-a-b+1,a+b)):
      if hand[i] > 0:
        break
    buf = sum(hand[i:])
    if buf > M:
      M = buf
print(M)


Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
n, k = list(map(int, input().split()))
que = list(map(int, input().split()))
ans = 0
pop_push = [(i, k-i) for i in range(k, math.ceil(k/2)-1, -1)]
for pop, push in pop_push:
    left_right = [(j, pop-j) for j in range(pop+1)]
    for left, right in left_right:
        ans = max(ans, sum(sorted(que[:left] + list(reversed(que))[:right])[push:]))
print(ans)

import math


n, k = list(map(int, input().split()))
que = list(map(int, input().split()))

ans = 0
max_pop_cnt = min(n, k)
for pop_cnt in range(max_pop_cnt+1):

    for right in range(pop_cnt+1):
        for push_cnt in range((k - pop_cnt)+1):
            ans = max(ans, sum(sorted(que[:pop_cnt-right] + list(reversed(que))[:right])[push_cnt:]))

print(ans)

Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
import copy
n,k=map(int,input().split())
l=list(map(int,input().split()))
lr=[[0,[]]]
ll=[[0,[]]]
sumr,suml=0,0
lrr=[]
llr=[]
for i in range(n):
  suml+=l[i]
  sumr+=l[-1-i]
  if l[i]<0:
    llr.append(l[i])
  if l[-1-i]<0:
    lrr.append(l[-1-i])
  llr1=copy.deepcopy(llr)
  lrr1=copy.deepcopy(lrr)
  lr.append([sumr,lrr1])
  ll.append([suml,llr1])
print(ll)
print(lr)
max=-10**10
for i in range(n+1):
  for j in range(n+1):
    if i+j>n or i+j>k:
      pass
    else:
      max1=lr[j][0]+ll[i][0]
      num=k-i-j
      list1=lr[j][1]+ll[i][1]
      list1=sorted(list1)
      for o in range(min(len(list1),num)):
        max1-=list1[o]
        if max1>max:
          max=max1
      if max1>max:
        max=max1
print(max)

import copy
n,k=map(int,input().split())
l=list(map(int,input().split()))
lr=[[0,[]]]
ll=[[0,[]]]
sumr,suml=0,0
lrr=[]
llr=[]
for i in range(n):
  suml+=l[i]
  sumr+=l[-1-i]
  if l[i]<0:
    llr.append(l[i])
  if l[-1-i]<0:
    lrr.append(l[-1-i])
  llr1=copy.deepcopy(llr)
  lrr1=copy.deepcopy(lrr)
  lr.append([sumr,lrr1])
  ll.append([suml,llr1])
max=-10**10
for i in range(n+1):
  for j in range(n+1):
    if i+j>n or i+j>k:
      pass
    else:
      max1=lr[j][0]+ll[i][0]
      num=k-i-j
      list1=lr[j][1]+ll[i][1]
      list1=sorted(list1)
      for o in range(min(len(list1),num)):
        max1-=list1[o]
        if max1>max:
          max=max1
      if max1>max:
        max=max1
print(max)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=[0]
for i in range(K+1):
    #print(i)
    for j in range(i+1):
        if N<=j:
            temp=sorted(V)
        elif j-i!=0:
            temp=sorted(V[:j]+V[max(i,j-i):])
        else:
            temp=sorted(V[:j])
        t=0
        for k in range(i):
            if temp[k]>=0:
                t=k+1
                break
        #print(temp,t)
        #if t==0:
        #    print(":",0)
        if t>K-i:
            #print(":",temp[K-i:])
            ans.append(sum(temp[K-i:]))
        elif (K-1-t)%2==1:
            if t>=2:
                #print(":",max(sum(temp[t-2:]),sum(temp[t:])))
                ans.append(max(sum(temp[t-2:]),sum(temp[t:])))
            else:
                #print(":",sum(temp[t:]))
                ans.append(sum(temp[t:]))
        else:
            #print(":",sum(temp[t-1:]))
            ans.append(sum(temp[t-1:]))
print(max(ans))

N,K=map(int,input().split())
V=list(map(int,input().split()))+[-10**8]
ans=0
for i in range(1,K+1):
    for j in range(1,min(i+1,N+1)):
        W=sorted(V[:j]+V[-min(i,N)-1+j:],reverse=True)[:-1]
        for k in range(0,K-i):
            if W[-1]<0:
                W.pop()
                if W==[]:
                    break
            else:
                break
        if ans<sum(W):
            ans=sum(W)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N, K = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0
for l in range(K+1):
    for r in range(K+1-l):
        if l + r > N:
            break
        get = lst[:l]
        get.extend(lst[N-r:])
        cnt = sum(get)
        get.sort()
        for i in range(min(K-l-r, l+r)):
            if get[i] >= 0:
                break
            tmp -= get[i]
        ans = max(ans, tmp)
print(ans)

N, K = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0
for l in range(K+1):
    for r in range(K+1-l):
        if l + r > N:
            break
        get = lst[:l]
        get.extend(lst[N-r:])
        cnt = sum(get)
        get.sort()
        for i in range(min(K-l-r, l+r)):
            if get[i] >= 0:
                break
            cnt -= get[i]
        ans = max(ans, cnt)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
from collections import deque
from copy import deepcopy

N, K = map(int, input().split())
V = list(map(int, input().split()))
q = deque()
for v in V:
    q.append(v)
ans = 0
jotai = []
for l in range(K + 1):
    for r in range(K + 1 - l):
        if l + r <= N and 2 * l + 2 * r > K:
            jotai.append([l, r, K - l - r])

print(jotai)

for i in range(len(jotai)):
    d = deepcopy(q)
    tmp = []
    for l in range(jotai[i][0]):
        tmp.append(d.popleft())
    # print(tmp)
    for r in range(jotai[i][1]):
        tmp.append(d.pop())
    # print(tmp)
    for k in range(jotai[i][2]):
        tmp.remove(min(tmp))
    # print(tmp)
    ans = max(sum(tmp), ans)
print(ans)


from collections import deque
from copy import deepcopy

N, K = map(int, input().split())
V = list(map(int, input().split()))
q = deque()
for v in V:
    q.append(v)
ans = 0
jotai = []
for l in range(K + 1):
    for r in range(K + 1 - l):
        if l + r <= N:
            jotai.append([l, r, K - l - r])

for i in range(len(jotai)):
    d = deepcopy(q)
    tmp = []
    for l in range(jotai[i][0]):
        tmp.append(d.popleft())
    # print(tmp)
    for r in range(jotai[i][1]):
        tmp.append(d.pop())
    # print(tmp)
    for k in range(jotai[i][2]):
        if tmp and min(tmp) < 0:
            tmp.remove(min(tmp))
    # print(tmp)
    ans = max(sum(tmp), ans)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
# -*- coding: utf-8 -*-

n,k=list(map(int, input().split()))
d=list(map(int, input().split()))
answer=0
for a in  range(k+1):
    for b in range(k-a+1):
        print(a,b,k-a-b)
        in_hand=d[:a]
        in_hand.extend(list(reversed(d[a:]))[:b])
        in_hand=sorted(in_hand)
        if k-a-b<0:
            continue
        in_hand=in_hand[k-a-b:]
        if sum(in_hand)>answer:
            answer=sum(in_hand)
print(answer)

def solve(string):
    n, k, *v = map(int, string.split())
    ans = 0
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum(base))
    return str(ans)
 
 
if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

# -*- coding: utf-8 -*-
 
n,k=list(map(int, input().split()))
d=list(map(int, input().split()))
answer=0
for a in  range(k+1):
    for b in range(k-a+1):
        if a+b<=k-a-b:
            continue
        if n<=a+b:
            continue
        in_hand=d[:a]
        in_hand+=in_hand[n-b:]
        in_hand=sorted(in_hand)
        in_hand=in_hand[k-a-b:]
        if sum(in_hand)>answer:
            answer=sum(in_hand)
print(answer)

# -*- coding: utf-8 -*-
 
n,max_k=list(map(int, input().split()))
d=list(map(int, input().split()))
answer=0
for k in range(1,max_k+1):
    for a in range(k+1):
        for b in range(k-a+1):
            if a+b<=k-a-b:
                continue
            if n<=a+b:
                in_hand=d
            else:
                in_hand=d[:a]
                in_hand+=d[n-b:]
            in_hand=sorted(in_hand)
            answer=max(answer,sum(in_hand[k-a-b:]))
print(answer)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
import bisect
n,k=map(int, input().split())
V=list(map(int, input().split()))
ans=0
for i in range(k+1):
  for j in range(k+1-i):
    if i+j>n:
      break  
    
    A=sorted(V[:i]+V[n-j:])
    a=min(n-i-j,bisect.bisect_left(A, 0))
    ans=max(ans,sum(S[a:]))
print(ans)

import bisect
n,k=map(int, input().split())
V=list(map(int, input().split()))
ans=0
for i in range(k+1):
  for j in range(k+1-i):
    if i+j>n:
      break  
    
    A=sorted(V[:i]+V[n-j:])
    a=min(n-i-j,bisect.bisect_left(A, 0))
    ans=max(ans,sum(A[a:]))
print(ans)

import bisect
n,k=map(int, input().split())
V=list(map(int, input().split()))
ans=0
for i in range(k+1):
  for j in range(k+1-i):
    if i+j>n:
      break  
    
    A=sorted(V[:i]+V[n-j:])
    a=min(k-i-j,bisect.bisect_left(A, 0))
    ans=max(ans,sum(A[a:]))
print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for i in range(min(N, K) + 1):
    for j in range(i+1):
        Juel = V[:j] + V[N-i+j:]
        Juel.sort()
        sum_v = 0
        for k in range(min(K-i, i)):
            Juel[k] = max(Juel[k], 0)
        ans = max(ans, sum(Juel))
    print(ans)
print(ans)

N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for i in range(min(N, K) + 1):
    for j in range(i+1):
        Juel = V[:j] + V[N-i+j:]
        Juel.sort()
        sum_v = 0
        for k in range(min(K-i, i)):
            Juel[k] = max(Juel[k], 0)
        ans = max(ans, sum(Juel))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):



N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = 0

for L in range(N+1):
  for R in range(N+1):
    if L+R > K:
      break
    if L+R > N:
      break
    get = V[:L]
    if R > 0:
      get += V[-R:]
    get.sort()
    print(get) ###
    
    rest = K - (L+R) 
    
    minus = sum((1 if x < 0 else 0 for x in get))
    if rest < minus:
      value = sum(get[rest:])
    else:
      value = sum((x for x in get if x > 0))
      
    if max_value < value:
      max_value = value
print(max_value)      




N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = 0

for L in range(N+1):
  for R in range(N+1):
    if L+R > K:
      break
    if L+R > N:
      break
    get = V[:L]
    if R > 0:
      get += V[-R:]
    get.sort()
        
    rest = K - (L+R) 
    
    minus = sum((1 if x < 0 else 0 for x in get))
    if rest < minus:
      value = sum(get[rest:])
    else:
      value = sum((x for x in get if x > 0))
      
    if max_value < value:
      max_value = value
print(max_value)      

Verdicts: Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
N,K = map(int, input().split())
V = list(map(int, input().split()))

ops = min(N,K)

ans = 0
for A in range(0,ops+1):
    l = V[:A]
    l.sort()
    for B in range(0,ops+1-A):
        ll = l[:]
        if B > 0:
            ll = l + V[-B:]
            ll.sort()
        for i in range(0,min(K-(A+B),A+B)):
            if ll[i] < 0:
                ll[i] = 0
            else:
                break
        print(A,B,ll)
        ans = max(sum(ll),ans)

print(ans)


N,K = map(int, input().split())
V = list(map(int, input().split()))

ops = min(N,K)

ans = 0
for A in range(0,ops+1):
    l = V[:A]
    l.sort()
    for B in range(max(0,(ops+1)//2-A),ops+1-A):
        ll = l
        if B > 0:
            ll = l + V[-B:]
            ll.sort()
        print(A,B,ll,ll[ops-(A+B):])
        ans = max(sum(ll[ops-(A+B):]),ans)

print(ans)


N,K = map(int, input().split())
V = list(map(int, input().split()))

ops = min(N,K)

ans = 0
for A in range(0,ops+1):
    l = V[:A]
    l.sort()
    for B in range(0,ops+1-A):
        ll = l[:]
        if B > 0:
            ll = l + V[-B:]
            ll.sort()
        for i in range(0,min(K-(A+B),A+B)):
            if ll[i] < 0:
                ll[i] = 0
            else:
                break
        ans = max(sum(ll),ans)

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Your friend gave you a dequeue D as a birthday present.  D is a horizontal cylinder that contains a row of N jewels.  The _values_ of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values.  In the beginning, you have no jewel in your hands.  You can perform at most K operations on D, chosen from the following, at most K times (possibly zero):    * Operation A: Take out the leftmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation B: Take out the rightmost jewel contained in D and have it in your hand. You cannot do this operation when D is empty.    * Operation C: Choose a jewel in your hands and insert it to the left end of D. You cannot do this operation when you have no jewel in your hand.    * Operation D: Choose a jewel in your hands and insert it to the right end of D. You cannot do this operation when you have no jewel in your hand.  Find the maximum possible sum of the values of jewels in your hands after the operations.

Submission attempts (in order):
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(min(n, k)):
    for right in range(min(n-left+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right+1))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp)
print(ans)


n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(min(n, k+1)):
    for right in range(min(n-left+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp)
print(ans)


Verdicts: Wrong Answer

Accepted