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):
N, K = map(int, input().split())
V = list(map(int, input().split()))
revV = list(reversed(V))

N = N + 1 
res = 0
AB = []
if N < K:
	AB = V
	k = min(K-len(AB), len(AB))
	for idx in range(k):
		if AB[idx] < 0:
			AB[idx] = 0
	res = max(res, sum(AB))
else:
	for a in range(N):
		for b in range(N):
			if a + b <= K:
				AB = V[:a] + revV[:b]
				AB.sort()
				k = min(K-len(AB), len(AB))
				for idx in range(k):
					if AB[idx] < 0:
						AB[idx] = 0
				res = max(res, sum(AB))
				print(a,b,AB)
print(res)

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

N = N + 1 
res = 0
AB = []
if N < K:
	AB = V
	k = min(K-len(AB), len(AB))
	for idx in range(k):
		if AB[idx] < 0:
			AB[idx] = 0
	res = max(res, sum(AB))
else:
	for a in range(N):
		for b in range(N):
			if a + b <= K:
				AB = V[:a] + revV[:b]
				AB.sort()
				k = min(K-len(AB), len(AB))
				for idx in range(k):
					if AB[idx] < 0:
						AB[idx] = 0
				res = max(res, sum(AB))
print(res)

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())
d=list(map(int,input().split()))
d=d*2
ans=0
for i in range(k):
  
  for j in range(i+1):
    have=[d[n+c-j] for c in range(i)] 
    have.sort()
    for h in range(k-i):
      if have[0]>=0:
        break
      del have[0]
    
    if sum(have)>ans:
      ans=sum(have)
print(ans)

n,k=map(int,input().split())
d=list(map(int,input().split()))
d=d*2
ans=0
for i in range(1,k+1):
  
  for j in range(i+1):
    have=[d[n+c-j] for c in range(i)] 
    have.sort()
    print(have)
    if i!=k:
      for h in range(k-i):
        if have==[] or have[0]>=0:
          break
        del have[0]
      
    if sum(have)>ans:
      ans=sum(have)
print(ans)


n,k=map(int,input().split())
d=list(map(int,input().split()))
d=d*2
ans=0
for i in range(1,min(k+1,n+1)):
  
  for j in range(i+1):
    have=[d[n+c-j] for c in range(i)] 
    have.sort()
    if i!=k:
      for h in range(k-i):
        if have==[] or have[0]>=0:
          break
        del have[0]
      
    if sum(have)>ans:
      ans=sum(have)
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):
N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
max_ope = min(N, K)
for put in range(K+1):
    if put > K//2:
        break
    get = min(K-put, N)
    for right in range(get+1):
        left = get - right
        jewels = A[:right] + A[N-left:]
        jewels.sort()
        value = sum(jewels)
        cnt = 0
        for jewel in jewels:
          if cnt > put:
            break
          if jewel < 0:
            value += abs(jewel)
        ans = max(ans, value)
print(ans)


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

ans = 0
max_ope = min(N, K)
for put in range(K+1):
    if put > K//2:
        break
    get = min(K-put, N)
    for right in range(get+1):
        left = get - right
        jewels = A[:right] + A[N-left:]
        jewels.sort()
        value = sum(jewels)
        cnt = 0
        for jewel in jewels:
          if cnt > put:
            break
          if jewel < 0:
            value += abs(jewel)
            cnt += 1
        ans = max(ans, value)
print(ans)


N, K = map(int, input().split())
jewels = [0] + list(map(int, input().split())) + [0]
ans = 0
for get in range(min(N, K)+1):
  put = get
  for left in range(get+1):
    right = get - left
    values = jewels[left:] + jewels[:N+1-right]
    sum_v = sum(values)
    minus_values = values.filter(lambda x: x<0)
    minus_values.sort()
    cnt = 0
    for v in minus_values:
      sum_v -= v
    ans = max(ans, sum_v)
print(ans)
    
  

N, K = map(int, input().split())
jewels = list(map(int, input().split())) + [0]
ans = 0
for get in range(1, min(N, K)+1):
  put = min(get, K-get)
  for left in range(get+1):
    right = get - left
    values = jewels[:left] + jewels[N-right:]
    sum_v = sum(values)
    minus_values = list(filter(lambda x: x<0, values))
    minus_values.sort()
    cnt = 0
    for v in minus_values:
      if cnt < put:
        sum_v -= v
        cnt += 1
      else:
          break
    ans = max(ans, sum_v)
print(ans)


Verdicts: Wrong Answer

Wrong Answer

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 numpy as np
import copy
# N,K = map(int,input().split())
# V = list(map(int,input().split()))
N = 17
K = 100
V = [i for i in range(N)]

V = [0 for i in range(N)] + V + [0 for i in range(N)] 

dp = {}


def search(start, end, k, own, discard=False):
    if k==K:
        return sum(own)
    key = tuple(own)
    if key in dp:
        return dp[key]
    val_Default = sum(own)
    val_A,val_B = 0,0
    if end-start >= 0 and not discard:
        val_A = search(start+1, end, k+1, own + [V[start]])
        val_B = search(start, end-1, k+1, own + [V[end]])
    if len(own) == 0 and discard:
        return val_Default
    val_Cs = []
    val_Ds = []
    for i,o in enumerate(own):
        own_new = copy.copy(own)
        own_new.pop(i)
        val_Cs.append(search(-1, -1, k+1, own_new, discard=True) )
        # val_Cs.append(search(start-1, end, k+1, own_new, discard=True) )
        # val_Ds.append(search(start, end+1, k+1, own_new, discard=True) )
    # print([val_Default, val_A, val_B], val_Cs , val_Ds)
    # dp[key] = max([val_Default, val_A, val_B] + val_Cs + val_Ds)
    dp[key] = max([val_Default, val_A, val_B] + val_Cs)
    # print(own, [val_Default, val_A, val_B], val_Cs, val_Ds)
    return dp[key]

r = search(N, 2*N-1, 0, [])
print(r)



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

sumval = 0
for l in range(min(K+1,N+1)):
    for r in range(min(K+1-l,N-l+1)):
        sV = sorted(V[:l]+ V[N-r:])
        # i_div = 0
        # for i_div in range(len(sV)):
        #     if sV[i_div] > 0:
        #         break
        # for sute in range(min(K-r-l+1,len(sV),i_div+1)):
        for sute in range(min(K-r-l+1,len(sV))):
            c = sum(sV[sute:])
            sumval = max(c,sumval)

print(sumval)

Verdicts: Time Limit Exceeded

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()))
lim = min(n, k)
ans = [0]

for a in range(lim+1):
    for b in range(lim-a+1):
        hand = sorted(v[:a]+v[n-b:])
        hs = sum(hand)
        for i in range(min(lim-a-b+1, a+b)):
            test = hand[i]
            if test < 0:
                hs -= test
        ans.append(hs)
print(max(ans))

n, k = map(int, input().split())
v = list(map(int, input().split()))
lim = min(n, k)
ans = [0]

for a in range(lim+1):
    for b in range(lim-a+1):
        hand = sorted(v[:a]+v[n-b:])
        hs = sum(hand)
        for i in range(min(lim-a-b, a+b)):
            test = hand[i]
            if test < 0:
                hs -= test
        ans.append(hs)
        print(a, b, hand, hs)
print(max(ans))

n, k = map(int, input().split())
v = list(map(int, input().split()))
lim = min(n, k)
ans = [0]

for a in range(lim+1):
    for b in range(lim-a+1):
        hand = sorted(v[:a]+v[n-b:])
        hs = sum(hand)
        for i in range(min(k-a-b, a+b)):
            test = hand[i]
            if test < 0:
                hs -= test
        ans.append(hs)
print(max(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):
#!/usr/bin/env python3.4

# abc128_d

import collections
import itertools

def find_index(iterable, func):
    i = 0
    for it in iterable:
        if func(it):
            break
        i += 1
    return i

def slice_deq(deq, n):
    return itertools.islice(deq, 0, n)

def main():
    # Input
    n, k = [int(s) for s in input().split()]
    vs = (int(s) for s in input().split())
    # Get ans
    vs = collections.deque(vs)
    R = min(n, k)
    def gene_tv():
        for i in range(1, R+1):
            vs.rotate(-1)
            vs.reverse()
            for _ in range(i+1):
                temp = list(slice_deq(vs, i))
                print(temp)
                temp.sort()
                l = find_index(temp, lambda x: x>0)
                l = min(l, k-i)
                yield sum(temp[l:])
                vs.rotate(-1)
            vs.rotate(-(i-1))
    ans = max(gene_tv())
    ans = max(ans, 0)
    # Output
    print(ans)

if __name__ == '__main__':
    main()



#!/usr/bin/env python3.4

# abc128_d

import collections
import itertools

def find_index(iterable, func):
    i = 0
    for it in iterable:
        if func(it):
            break
        i += 1
    return i

def slice_deq(deq, n):
    return itertools.islice(deq, 0, n)

def main():
    # Input
    n, k = [int(s) for s in input().split()]
    vs = (int(s) for s in input().split())
    # Get ans
    vs = collections.deque(vs)
    R = min(n, k)
    def gene_tv():
        for i in range(1, R+1):
            vs.rotate(-1)
            vs.reverse()
            for _ in range(i+1):
                temp = list(slice_deq(vs, i))
                temp.sort()
                l = find_index(temp, lambda x: x>0)
                l = min(l, k-i)
                yield sum(temp[l:])
                vs.rotate(-1)
            vs.rotate(-(i-1))
    ans = max(gene_tv())
    ans = max(ans, 0)
    # Output
    print(ans)

if __name__ == '__main__':
    main()



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):
import heapq
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=0
for i in range(k+1):
    a_cp=a.copy()

    tmp=a_cp[:i]
    a_cp[i:]
    for j in range(k+1-i):
        cal=tmp+a_cp[min(n-j,0):]
        
        heapq.heapify(cal)
        ans=max(ans,sum(cal))
        for _ in range(k-i-j):
            if len(cal)>0:
                heapq.heappop(cal)
                ans=max(ans,sum(cal))
            else:
                break
print(ans)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))

from collections import Counter 
from collections import defaultdict
from collections import deque
import itertools
import heapq
import sys
sys.setrecursionlimit(10**6)

n,m=input_list()
a=deque(input_list())
ans=0
for get_num in range(m+1):
    ret_num=min(m-get_num,get_num)
    if get_num>n:
        get_num=n
        ret_num=min(m-get_num,get_num)
    
    for get_left in range(get_num+1):
        cal=[]
        get_right=get_num-get_left
        val=0
        for i in range(get_left):
            val+=a[i]
            heapq.heappush(cal,a[i])
        for i in range(get_right):
            ii=n-1-i
            val+=a[ii]
            heapq.heappush(cal,a[ii])
        for _ in range(ret_num):
            p_val=heapq.heappop(cal)
            if p_val>0:
                break
            val-=p_val
        ans=max(ans,val)
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())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[cnt] = max(0,num[cnt])
            ans = max(ans,sum(num))
print(ans)

n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[h] = max(0,num[h])
            ans = max(ans,sum(num))
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())
A = list(map(int,input().split()))

ans = - 10**7
for i in range(min(N,K)+1):
  for j in range(min(N,K)+1-i
    if j == 0:
      st = A[:i]
    else:
      st = A[:i]+ A[-j:]
    st.sort(reverse = 1)):
    for suteru in range(K - i - j):
      ans = max(ans, sum(st[:i+j-suteru]))
    
print(ans)

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

ans = - 10**7
for i in range(min(N,K)+1):
  for j in range(min(N,K)+1-i):
    if j == 0:
      st = A[:i]
    else:
      st = A[:i]+ A[-j:]
    st.sort(reverse = 1)
    for suteru in range(K - i - j):
      ans = max(ans, sum(st[:i+j-suteru]))
    
print(ans)

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

ans = 0

for i in range(min(N,K)+1):
  for j in range(min(N,K)+1-i):
    if j == 0:
      st = A[:i]
    else:
      st = A[:i]+ A[-j:]
    st.sort(reverse = 1)
    for suteru in range(K - i - j+1):
      ans = max(ans, sum(st[:i+j-suteru]))
    
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):
import heapq

N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = -float('inf')
for ai in range(K+1):
  for bi in range(K+1):
    if ai+bi > min(K,N): continue
    have = []
    if ai != 0: [heapq.heappush(have, v) for v in V[:ai]]
    if bi != 0: [heapq.heappush(have, v) for v in V[-bi:]]
    for i in range(K-ai-bi+1):
      if len(have) != 0: heapq.heappop(have)
    ans = max(ans,sum(have))
print(ans)

import heapq

N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = -float('inf')
for ai in range(K+1):
  for bi in range(K+1):
    if ai+bi > K or ai > N or bi > N: continue
    have = []
    if ai != 0: [heapq.heappush(have, v) for v in V[:ai]]
    if bi != 0: [heapq.heappush(have, v) for v in V[-bi:]]
    for i in range(K-ai-bi+1):
      if len(have) != 0: heapq.heappop(have)
    ans = max(ans,sum(have))
print(ans)

import heapq

N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = -float('inf')
for ai in range(K+1):
  for bi in range(K+1):
    if ai+bi > min(K,N): continue
    have_plus = []
    have_neg = []
    if ai != 0: [heapq.heappush(have_plus, v) if v >= 0 else heapq.heappush(have_neg, v) for v in V[:ai]]
    if bi != 0: [heapq.heappush(have_plus, v) if v >= 0 else heapq.heappush(have_neg, v) for v in V[N-bi:]]
    for i in range(K-ai-bi):
      if len(have_neg) != 0:
        heapq.heappop(have_neg)
    ans = max(ans,sum(have_plus)+sum(have_neg))
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 = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]


# 0<=i<=k//2



ans = 0
for k_i in range(k):
  for i in range(k_i//2+1):
    
    for j in range(k_i-i+1):
      #print(j)
      hand_tmp = v[:j] + v[::-1][:k_i-i-j]
      hand_tmp.sort()
      #print(hand_tmp)
      hand_tmp = hand_tmp[i:]
      ans_tmp = sum(hand_tmp)
      if ans_tmp > ans:
        ans = ans_tmp
    
      
print(ans)
    

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


# 0<=i<=k//2


ans = 0

for k_i in range(min(2*n+1,k+1)):
  
  
  rem_min = 0
  if k_i > n:
    rem_min = k_i - n
  for rem in range(rem_min, k_i//2+1):
    
    for j in range(k_i-rem+1):
      #print(j)
      hand_tmp = v[:j] + v[::-1][:k_i-rem-j]
      hand_tmp.sort()
      #print(hand_tmp)
      
      hand_tmp = hand_tmp[rem:]
      ans_tmp = sum(hand_tmp)
      if ans_tmp > ans:
        ans = ans_tmp
        
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()))
mini = min(n, k)
value = 0
for a in range(mini + 1):
  for b in range(mini - a + 1):
    c = k - a - b
    j = v[:a] + v[n-b:]
    j.sort(reverse=True)
    for _ in range(c):
      if j[-1] < 0:
        j.pop()
      else:
        break
    value = max(value, sum(j))
print(value)

n, k = map(int, input().split())
v = list(map(int, input().split()))
mini = min(n, k)
value = 0
for a in range(mini + 1):
  for b in range(mini - a + 1):
    c = k - a - b
    j = v[:a] + v[n-b:]
    j.sort(reverse=True)
    for _ in range(c):
      if j and j[-1] < 0:
        j.pop()
      else:
        break
    value = max(value, sum(j))
print(value)

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):
# -*- coding:utf-8 -*-
import copy

def solve():
    N, K = list(map(int, input().split()))
    V = list(map(int, input().split()))
    
    ans = 0
    M = min(N,K)
    for l in range(M+1):
        having = []
        for r in range(M+1):
            if l+r > K: break
            if l+r == 0: continue
            
            having = V[:l] + V[::-1][:r]
            having.sort(reverse=True)

            restK = K - (l+r)

            for i in range(restK):
                if having[-1] < 0:
                    having.pop()
                    continue
                break

            ans = max(ans, sum(having))
    
    print(ans)

if __name__ == "__main__":
    solve()


# -*- coding:utf-8 -*-
import sys
import heapq


def solve():
    N, K = list(map(int, sys.stdin.readline().split()))
    Vs = list(map(int, sys.stdin.readline().split()))

    ans = 0
    for i in range(0, K+1):
        for j in range(0, K+1):
            if i+j > K: break
            if i+j > N: break

            _Vs = Vs[::-1]
            have = Vs[0:i]+_Vs[0:j]
            have.sort(reverse=True)

            M = i+j
            while M < K:
                if len(have) == 0: break
                if have[-1] < 0:
                    have.remove(have[-1])
                    M += 1
                    continue
                break

            ans = max(ans, sum(have))

    print(ans)



if __name__ == "__main__":
    solve()


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 = list(map(int, input().split()))
Gem = list(map(int, input().split()))
gem = []
Max = Gem[0]
r = min(n,k)
for i in range(r + 1):
    gem = []
    for j in range(r - i + 1):
        gem = Gem[0:i]
        gem += Gem[n - j:n]
        dif = r - (i + j)
        for k in range(dif + 1):
            if len(gem) == 0:
                break
            M = gem.index(min(gem))
            if gem[M] < 0:
                del gem[M]
            else:
                break
        if len(gem) == 0:
            Max = max(Max,0)
        elif Max < sum(gem):
            Max = sum(gem)
print(Max)

n, k = list(map(int, input().split()))
Gem = list(map(int, input().split()))
gem = []
Max = Gem[0]
r = min(n,k)
for i in range(r + 1):
    gem = []
    for j in range(r - i + 1):
        gem = Gem[0:i]
        gem += Gem[n - j:n]
        dif = k - (i + j)
        for s in range(dif):
            if len(gem) == 0:
                break
            M = gem.index(min(gem))
            if gem[M] < 0:
                del gem[M]
            else:
                break
        if len(gem) == 0:
            Max = max(Max,0)
        elif Max < sum(gem):
            Max = sum(gem)
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):
import heapq
n,k=map(int,input().split())
v=[int(x) for x in input().split()]

print(n,k)
print(v)

p = list()
m = min(n,k)
t = 0

for h in range(1,m+1):
  for i in range(0,h+1):
    a = b = 0
    p.clear()
    for j in range(0,i):
      if v[j]<0:
        p.append(v[j])
      a += v[j]
    for j in range(1,h-i+1):
      if v[-j]<0:
        p.append(v[-j])
      b += v[-j]
    p.sort(reverse=True)
    n = a+b
    for i in range(min(k-h,len(p))):
      n -= p.pop()
    t = max(t,n)
print(t if t > 0 else 0)


import heapq
n,k=map(int,input().split())
v=[int(x) for x in input().split()]

p = list()
m = min(n,k)
t = 0

for h in range(1,m+1):
  for i in range(0,h+1):
    a = b = 0
    p.clear()
    for j in range(0,i):
      if v[j]<0:
        p.append(v[j])
      a += v[j]
    for j in range(1,h-i+1):
      if v[-j]<0:
        p.append(v[-j])
      b += v[-j]
    p.sort(reverse=True)
    n = a+b
    for i in range(min(k-h,len(p))):
      n -= p.pop()
    t = max(t,n)
print(t if t > 0 else 0)


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()))
v = list(map(int, input().split()))
l = 0
r = 0
a = 0
m = min(n, k)+1
have = []
total = 0
ans = 0
for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = k-l-r-1
        data = have[0]+have[1]
        data.sort()
        for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total
print(ans)


n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
l = 0
r = 0
a = 0
m = min(n, k)
have = []
total = 0
ans = 0
for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = m-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(a):
            if data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total
print(ans)


n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
l = 0
r = 0
a = 0
m = min(n, k)+1
have = []
total = 0
ans = 0
for r in range(m):
    for l in range(m-r):
        have = []
        have.append(v[:r])
        if l != 0:
            have.append(v[-l:])
        else:
            have.append([])
        a = k-l-r
        data = have[0]+have[1]
        data.sort()
        for i in range(len(data)):
            if i < a and data[i] < 0:
                data[i] = 0
        total = sum(data)
        if total > ans:
            ans = total
print(ans)


Verdicts: Wrong Answer

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())
v = list(map(int, input().split()))
cum = [0] * (n+1)

for i in range(n):
    cum[i+1] = cum[i] + v[i]

ans = 0
cnt = 0
for i in range(n):
    for j in range(n):
        if i > j:
            continue
        l = (j - i)
        if n - l > k:
            continue
        a = v[:i] + v[j+1:]
        b = a[:]
        a.sort()
        tmp = cum[n] - (cum[j+1] - cum[i])
        tmp1 =tmp
        for x in range(k - (n-l)):
            if x >= len(a) or a[x] >= 0:
                break
            tmp -= a[x]
        ans = max([ans, tmp])
        cnt += 1

print(ans)


n,k=map(int,input().split())
v = list(map(int, input().split()))
cum = [0] * (n+1)

for i in range(n):
    cum[i+1] = cum[i] + v[i]

ans = 0
cnt = 0
for i in range(n):
    for j in range(n):
        if i > j:
            continue
        l = (j - i + 1)
        if n - l > k:
            continue
        a = v[:i] + v[j+1:]
        b = a[:]
        a.sort()
        tmp = cum[n] - (cum[j+1] - cum[i])
        tmp1 =tmp
        for x in range(k - (n-l)):
            if x >= len(a) or a[x] >= 0:
                break
            tmp -= a[x]
        ans = max([ans, tmp])
        print('{}:{}:{}'.format(b, tmp1, tmp))
        cnt += 1
ans = max([ans, v[0], v[-1]])
if k >= 3 and n >= 2:
    ans = max([ans, v[1], v[-2]])
if k >= 4 and n >= 3:
    ans = max([ans, sum(v[1:3]), sum(v[-3:-1])])
print(ans)


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

ans = 0
cnt = 0
for i in range(n+1):
    for j in range(n+1):
        if i + j > n or i + j > k:
            continue
        if j == 0:
            a = v[:i]
        else:
            a = v[:i] + v[-j:]
        tmp = sum(a)
        a.sort()
        for x in range(min([k-(i+j), i+j])):
            if a[x] >= 0:
                break
            tmp -= a[x]
        ans = max([ans, tmp])
        cnt += 1

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):
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n,k=map(int,input().split())
v1=list(map(int,input().split()))
v2=v1[::-1]
r=min(n,k)
ans=0
for i in range(r+1):
    for j in range(i+1):
        tmp=v1[:j]+v2[:i-j]
        tmp.sort()
        for k in range(min(k-i,i)):
            if tmp[k]<0:
                tmp[k]=0
        ans=max(ans,sum(tmp))

print(ans)

n, k = map(int, input().split())
v = list(map(int, input().split()))
r = min(n, k)
ans = -float('inf')
for i in range(r+1):
    a = v[:i]
    for j in range(r+1-i):
        candi=a[:]
        if j !=0 :candi += v[-j:]
        candi.sort()
        for t in range(k-i-j):
            if not 0<=t<len(candi):break
            if candi[t] < 0:
                candi[t] = 03023
            else:
                break
        candi = sum(candi)
        ans = max(candi, ans)
print(ans)


#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n,k=map(int,input().split())
v1=list(map(int,input().split()))
v2=v1[::-1]
r=min(n,k)
ans=0
for i in range(r+1):
    for j in range(i+1):
        tmp=v1[:j]+v2[:i-j]
        tmp.sort()
        for l in range(min(k-i,i)):
            if tmp[l]<0:
                tmp[l]=0
        ans=max(ans,sum(tmp))

print(ans)

Verdicts: Wrong Answer

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,*v=map(int,open(0).read().split())
m=0
for i in range(n+1):
 for j in range(min(k,n)-i+1):
  t=sorted(v[:i]+v[:~j])
  while t and(k-i-j)*t[0]<0:t.pop(0);j+=1
  m=max(m,sum(t))
print(m)

n,k,*v=map(int,open(0).read().split())
m=0
r=range
for i in r(n+1):
 for j in r(min(k,n)-i+1):
  t=sorted(v[:i]+v[-j:]*(j>0))[::-1];c=k-i-j
  while c*t[-1]<0:t.pop();c-=1
  m=max(m,sum(t))
print(m)

n,k,*v=map(int,open(0).read().split())
m=0
r=range
for i in r(n+1):
 for j in r(min(k,n)-i+1):
  t=sorted(v[:i]+v[:-j:-1])
  while t and(k-i-j)*t[0]<0:t.pop(0);j+=1
  m=max(m,sum(t))
print(m)

n,k,*v=map(int,open(0).read().split());print(max(sum(v[:i-j]+v[n-j:])-sum(sorted(x*(x<0)for x in v[:i-j]+v[n-j:])[:k-i])for i in range(min(n,k)+1)for j in range(i)))

Verdicts: Wrong Answer

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):
import numpy as np 

N, K = map(int, input().split())
vs = np.array([int(v) for v in input().split()])
ak = min(N + 1, K + 1)
max_value = 0

for a in range(ak):
    bk = min(N - a + 1, K - a + 1)
    for b in range(bk):
        n_remove = K - a - b
        l = np.sum(vs[:a]) if a > 0 else 0
        r = np.sum(vs[-b:]) if b > 0 else 0
        print(l, r)
        
        if a > 0 and b > 0:
            pos = np.r_[vs[:a], vs[-b:]]
            order = np.argsort(pos)
            pos = pos[order]
        elif a > 0:
            pos = vs[:a]
            order = np.argsort(pos)
            pos = pos[order]
        elif b > 0:
            pos = vs[-b:]
            order = np.argsort(pos)
            pos = pos[order]
        else:
            pos = np.array([])
            
        n_minus = len(np.where(pos < 0)[0])
        
        value = l + r - np.sum(pos[:n_minus]) if n_minus < n_remove else l + r - np.sum(pos[:n_remove])
        print(a, b, value)
        max_value = max(value, max_value)

print(max_value)

import numpy as np 

N, K = map(int, input().split())
vs = np.array([int(v) for v in input().split()])
ak = min(N + 1, K + 1)
max_value = 0

for a in range(ak):
    bk = min(N - a + 1, K - a + 1)
    for b in range(bk):
        n_remove = K - a - b
        l = np.sum(vs[:a]) if a > 0 else 0
        r = np.sum(vs[-b:]) if b > 0 else 0
        
        if a > 0 and b > 0:
            pos = np.r_[vs[:a], vs[-b:]]
            order = np.argsort(pos)
            pos = pos[order]
        elif a > 0:
            pos = vs[:a]
            order = np.argsort(pos)
            pos = pos[order]
        elif b > 0:
            pos = vs[-b:]
            order = np.argsort(pos)
            pos = pos[order]
        else:
            pos = np.array([])

        n_minus = len(np.where(pos < 0)[0])
        
        value = l + r - np.sum(pos[:n_minus]) if n_minus < n_remove else l + r - np.sum(pos[:n_remove])
        
        max_value = max(value, max_value)

print(max_value)

Verdicts: Wrong Answer

Accepted