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()))
KK = K
K = min(N,K)

ans = 0
for k in range(1,K):
    for i in range(k+1):
        R = V[-(k-i):]
        if len(R) == N:
            R = []
        print(R)
        L = V[:i]+R+[0]
        L.sort()
        zero_index = min(L.index(0),KK-k)
        res = sum(L[zero_index:])
        ans = max(ans,res)
print(ans)

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

ans = 0
for i in range(k+1):
	for j in range(k-i+1):
		# print(i,j)
		a = v[:i]
		b = v[-j:]
		if len(b) == n:
			b = []
		ab = sorted(a+b+[0])
		idx = min(ab.index(0),idx_k-i-j)
		ans = max(ans,sum(ab[idx:]))
		# print(a,b,ab,idx,sum(ab[idx:]))
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):
from itertools import combinations
from bisect import bisect_left
N, K = map(int,input().split())
A = list(map(int,input().split()))

ans=0

for i,j in combinations(range(N+2),2):
  l = sorted(A[0:i]+A[j-1:N])
  if len(l)<=K:
    m = bisect_left(l,0)
  	ans = max(ans,sum(l[min(K-len(l),m):]))
print(ans)


from itertools import combinations
from bisect import bisect_left
N, K = map(int,input().split())
A = list(map(int,input().split()))

ans=0

for i,j in combinations(range(N+2),2):
  l = sorted(A[0:i]+A[j-1:N])
  if len(l)<=K:
    m = bisect_left(l,0)
    ans = max(ans,sum(l[min(K-len(l),m):]))
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 sys
n, k = [int(i) for i in sys.stdin.readline().split()]
v_ls = [int(i) for i in sys.stdin.readline().split()]
inv_v_ls = v_ls[::-1]
sum_a_b = min(n, k) + 1
best = 0
for a in range(sum_a_b):
    for b in range(sum_a_b - a):
        ls = v_ls[:a] + inv_v_ls[:b]
        ls.sort()
        for c in range(k - a - b):
            if c >= len(ls):
                break
            score = sum(ls[c:])
            if score > best:
                best = score
            if ls[c] > 0:
                break
print(best)

import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
v_ls = [int(i) for i in sys.stdin.readline().split()]
inv_v_ls = v_ls[::-1]
sum_a_b = min(n, k) + 1
best = 0
for a in range(sum_a_b):
    for b in range(sum_a_b - a):
        ls = v_ls[:a] + inv_v_ls[:b]
        ls.sort()
        for c in range(sum_a_b - a - b):
            if c >= len(ls):
                break
            score = sum(ls[c:])
            print(score)
            if score > best:
                best = score
            if ls[c] > 0:
                break
print(best)

import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
v_ls = [int(i) for i in sys.stdin.readline().split()]
inv_v_ls = v_ls[::-1]
sum_a_b = min(n, k) + 1
best = 0
for a in range(sum_a_b):
    for b in range(sum_a_b - a):
        ls = v_ls[:a] + inv_v_ls[:b]
        ls.sort()
        for c in range(k + 1 - a - b):
            if c >= len(ls):
                break
            score = sum(ls[c:])
            if score > best:
                best = score
            if ls[c] > 0:
                break
print(best)

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 i in range(min(k,n)+1):
    for j in range(min(k,n)-i+1):
        print(v[:i])
        print(v[:~j:-1])
        t=sorted(v[:i]+v[:~j:-1])
        for l in range(min(min(n,k)-i-j,len(t))):
            if t[l]<0:
                t[l]=0
        ans=max(ans,sum(t))

print(ans)

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

ans=0
for i in range(min(k,n)+1):
    for j in range(min(k,n)-i+1):
        t=sorted(v[:i]+v[:~j:-1])
        for l in range(min(min(n,k),len(t))):
            if t[l]<0:
                t[l]=0
        ans=max(ans,sum(t))

print(ans)

n,k = map(int,input().split())
v = list(map(int,input().split()))
 
m=[]
for i in range(min(k,n)+1):
    for j in range(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.append(sum(t))
print(max(m))

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()))
L,R = [0]*(K),[0]*(K)
L[0] = max(0,V[0])
R[0] = max(0,V[-1])
for i in range(min(N,K)+1):
    part = V[:i]
    part.sort()
    for j in range(min(K-i,i)):
        if part[0] < 0:
            part.pop(0)
        L[i+j] = max(L[i+j],sum(part))
V.reverse()
for i in range(min(N,K)+1):
    part = V[:i]
    part.sort()
    for j in range(min(K-i,i)):
        if part[0] < 0:
            part.pop(0)
        R[i+j] = max(R[i+j],sum(part))
R[-1] = max(0,sum(part())
ans = max(R[-1],L[-1])
for i in range(K-1):
    ans = max(ans,L[i]+R[-i-2])
print(L)
print(R)
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: 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()))

ans=0

for a in range(50):
  for b in range(50):
    if a+b <= min(n,k):
      li=v[:a]+v[n-b:]
      sumv = sum(li)
      li.sort()
      for i in range(min(k-a-b,len(li))):
        if li[i] < 0:
          li[i] = 0:
        else:
          break:
      ans=max(ans,sum(li))
      
print(ans)
            
      

n,k=map(int,input().split())
v=list(map(int,input().split()))
 
ans=0
 
for a in range(50):
  for b in range(50):
    if a+b <= min(n,k):
      li=v[:a]+v[n-b:]
      sumv = sum(li)
      li.sort()
      for i in range(min(k-a-b,len(li))):
        if li[i] < 0:
          li[i] = 0
        else:
          break
      ans=max(ans,sum(li))
      
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,ki=map(int,input().split())
v=list(map(int,input().split()))

m=min(n,ki)
ans=0

for i in range(m+1):
    for j in range(i+1):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v[k])
        for kz in range(i-j):
            if len(v)>0:
                q.append(v[n-1-kz])
        for l in range(len(q)):
            if q[l]>0:
                tmp+=q[l]
        ans=max(ans,tmp)
        
print(ans)

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

m=min(n,k)
ans=0

for i in range(m+1):
    for j in range(i):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v.pop(0))
        for k in range(i-j):
            if len(v)>0:
                q.append(v.pop(-1))
        
        for l in range(len(q)):
            if q[l]>0:
                tmp+=q[l]
        ans=max(ans,tmp)
print(ans)
  

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

m=min(n,ki)
ans=0

for i in range(m+1):
    for j in range(i+1):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v[k])
        for kz in range(i-j):
            if len(v)>0:
                q.append(v[n-1-kz])
        tmp=sum(q)
        q.sort()
        for l in range(ki-i):
            if l<len(q) and q[l]<0:
                tmp-=q[l]
        ans=max(ans,tmp)
        
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):
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
N,K = map(int,input().split())
VN =  [int(i) for i in input().split()]

ans = 0
temp = 0

for i in range(min(N,K)):
    for j in range(min(K-i,N-i)):
        now = 0
        if i + j > K-2:
            break
       
        tmp_list = []
        
        for l in range(i):
            now += VN[l]
            tmp_list.append(VN[l])
    
        for m in range(j):
            now += VN[N-1-m]
            tmp_list.append(VN[N-1-m])
        
        tmp_list.sort()
        
        for n in range(N-i-j-2):
            if n >= len(tmp_list)-1:
                break
            if tmp_list[n] >= 0:
                break
            now -= tmp_list[n]
        ans = max(ans,now)

print(ans)

import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
N,K = map(int,input().split())
VN =  [int(i) for i in input().split()]

ans = 0
temp = 0

for i in range(min(N,K)+1):
    for j in range(min(K-i,N-i)+1):
        now = 0
        if i + j > min(N,K):
            break
       
        tmp_list = []
        
        for l in range(i):
            now += VN[l]
            tmp_list.append(VN[l])
    
        for m in range(j):
            now += VN[N-1-m]
            tmp_list.append(VN[N-1-m])
        
        tmp_list.sort()
        
        for n in range(K-i-j):
            if n >= len(tmp_list):
                break
            if tmp_list[n] >= 0:
                break
            now -= tmp_list[n]
        ans = max(ans,now)

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):
import numpy as np
n,k = map(int,input().split())

arr = list(map(int,input().split()))
s = [0 for i in range(n)]
temp = 0

ans = 0
for i in range(n):
    temp += arr[i]
    s[i] = temp

for i in range(1,k+1):
    upper = min(n,i)
    for j in range(upper+1):
        v = 0
        a = []
        for l in range(j):
            v += arr[l]
            a.append(arr[l])
        for l in range(1,i+1-j):
            v+= arr[-l]
            a.append(arr[-l])
        a.sort()
        # print(a,v)
        if k-i > 0:
            up = min(k-i-1,i)
            for l in range(up):
                if a[l] < 0:
                    v -= a[l]
                else:
                    break
        if v > ans:
            ans = v

print(ans)




import numpy as np
n,k = map(int,input().split())

arr = list(map(int,input().split()))
s = [0 for i in range(n)]
temp = 0
ans = 0

for i in range(1,k+1):
    upper = min(n,i)
    for j in range(upper+1):
        v = 0
        a = []
        for l in range(j):
            v += arr[l]
            a.append(arr[l])
        for l in range(1,upper+1-j):
            v+= arr[-l]
            a.append(arr[-l])
        a.sort()
        # print(a,v)
        up = min(k-upper,i)
        for l in range(up):
            if a[l] < 0:
                v -= a[l]
            else:
                break
        if v > ans:
            ans = v

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):
#!/usr/bin/env python3

import heapq

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

max_try = min(n, k)
ans = 0

for a in range(0, max_try+1):
    for b in range(0, max_try+1-a):
        c = k-(a+b)
        # print(a, b, c, "", end="")
        # print(a, b, c)
        ans_tmp = 0
        garbage = []
        heapq.heapify(garbage)
        for i in range(a):
            num = v[i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        for i in range(b):
            num = v[-1-i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        # print(garbage)
        for i in range(c):
            # print(garbage)
            if len(garbage) == 0:
                break
            num = -heapq.heappop(garbage)
            # print(num)
            ans_tmp += num
        # print()
        print(ans_tmp)
        ans = max(ans, ans_tmp)

print(ans)


#!/usr/bin/env python3

import heapq

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

max_try = min(n, k)
ans = 0

for a in range(0, max_try+1):
    for b in range(0, max_try+1-a):
        c = k-(a+b)
        # print(a, b, c, "", end="")
        # print(a, b, c)
        ans_tmp = 0
        garbage = []
        heapq.heapify(garbage)
        for i in range(a):
            num = v[i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        for i in range(b):
            num = v[-1-i]
            ans_tmp += num

            if num < 0:
                heapq.heappush(garbage, num)

        # print(garbage)
        for i in range(c):
            # print(garbage)
            if len(garbage) == 0:
                break
            num = -heapq.heappop(garbage)
            # print(num)
            ans_tmp += num
        # print()
        # print(ans_tmp)
        ans = max(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()))
ans = 0
for pull in range(k + 1):
    for back in range(k):
        if pull + back != k:
            continue
        if pull >= n:
            hand = V
        else:
            for l in range(pull+1):
                r = pull - l
                if r > 0:
                    hand = V[:l] + V[-r:]
                else:
                    hand = V[:l]
        hand = sorted(hand, reverse=True)
        for _ in range(back):
            if len(hand) == 0:
                break
            if hand[-1] < 0:
                hand.pop()
            else:
                break
        ans = max(ans, sum(hand))
print(ans)

n, k = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for pull in range(k + 1):
    for back in range(k):
        if pull + back != k:
            continue
        for l in range(pull+1):
            r = pull - l
            if r > 0:
                hand = V[:l] + V[-r:]
            else:
                hand = V[:l]
            if pull >= n:
                hand = V
            hand = sorted(hand, reverse=True)
            for _ in range(back):
                if len(hand) == 0:
                    break
                if hand[-1] < 0:
                    hand.pop()
                else:
                    break
            ans = max(ans, sum(hand))
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):
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
from collections import deque
import heapq

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

ans = 0

maxPop = min(N,K)

for li in range(maxPop+1):
    
    for ri in range(maxPop+1-li):
        
        D = deque(V)
        jew = [] 

        
        maxPush = maxPop - (ri+li)
        
        for i in range(li):
            jew.append(D.popleft())
        
        for i in range(li):
            jew.append(D.popright())
        
        jew.sort()
        
        for i in range(min(maxPush, len(jew))):
            if jew[i] < 0:
                jew[i] = 0
        
        ans = max(ans,sum(jew))

print(ans)

# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
from collections import deque
import heapq

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

ans = 0

maxPop = min(N,K)

for li in range(maxPop+1):
    
    for ri in range(maxPop+1-li):
        
        D = deque(V)
        jew = [] 

        
        maxPush = K - (ri+li)
        
        for i in range(li):
            jew.append(D.popleft())
        
        for i in range(ri):
            jew.append(D.pop())
        
        jew.sort()
        
        for i in range(min(maxPush, len(jew))):
            if jew[i] < 0:
                jew[i] = 0
        
        ans = max(ans,sum(jew))

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 heapq import heappop, heappush
from collections import deque
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
Q = deque()
ans = 0
R = min(N,K)
for l in range(R):
  H = []
  if l >= 1:
    for i in range(l):
      heappush(H,V[i])
  for r in range(R-l):
    if r >= 1:
      for i in range(r):
        heappush(H,V[N-1-i])
    ans = max(ans,sum(H))
    for i in range(min(len(H),K-l-r)):
      Q.append(heappop(H))
      ans = max(ans,sum(H))
print(ans)

from heapq import heappop, heappush
from collections import deque
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
Q = deque()
ans = 0
R = min(N,K)
for l in range(R):
  H = []
  for r in range(R-l):
    if l >= 1:
      for i in range(l):
        heappush(H,V[i])
    if r >= 1:
      for i in range(r):
        heappush(H,V[N-1-i])
    ans = max(ans,sum(H))
    for i in range(min(len(H),K-l-r)):
      p = heappop(H)
      if p <= 0:
        ans = max(ans,sum(H))
      else:
        break
print(ans)

from heapq import heappop, heappush
from collections import deque
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
Q = deque()
ans = 0
R = min(N,K)+1
for l in range(R):
  H = []
  for r in range(R-l):
    if l >= 1:
      for i in range(l):
        heappush(H,V[i])
    if r >= 1:
      for i in range(r):
        heappush(H,V[N-1-i])
    ans = max(ans,sum(H))
#    print(H,sum(H),l,r)
    for i in range(min(len(H),K-l-r)):
      p = heappop(H)
      if p <= 0:
        ans = max(ans,sum(H))
      else:
        break
#      print(H,sum(H))
print(ans)

from heapq import heappush, heappop, heapify
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
ans = 0

for i in range(min(K,N)+1):
  for l in range(i+1):
    H = []
    r = i-l
#    print(i,l,r)
    H.extend(V[:l])
    if r > 0:
      H.extend(V[-r:])
    heapify(H)
    for j in range(min(K-i,i)):
      if H[0] >= 0:
        break
      heappop(H)
    ans = max(ans,sum(H))
#  print(H)
print(ans)

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):
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for i in range(1,K+1):
    for j in range(i+1):
        rec = V[:i-j]+V[N-j:]
        rec.sort(reverse=True)
        away = max(min(0, i, K-i),0)
        for l in range(away+1):
            recsum = sum(rec[:i-l])
            if recsum > ans:
                ans=recsum
print(ans)

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
KN = min(K,N)
for i in range(1,KN+1):
    for j in range(i+1):
        rec = V[:i-j]+V[N-j:]
        rec.sort(reverse=True)
        away = max(min(i, K-i),0)
        for l in range(away+1):
            recsum = sum(rec[:i-l])
            if recsum > ans:
                ans=recsum
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):
a,k=map(int,input().split())
L=list(map(int,input().split()))
ans=0
 
for i in range(min(k,a)+1):
  for j in range(min(k,a)-i+1):
    S=L[:i]+L[a-j:]
    S.sort()
    x=0
    while x < k-(j+i):
      if S[x]>=0:
        break
      x+=1
    ans=max(ans,sum(S)-sum(S[:x]))
    
print(ans)

a,k=map(int,input().split())
L=list(map(int,input().split()))
ans=0
 
for i in range(min(k,a)+1):
  for j in range(min(k,a)-i+1):
    S=[0]+L[:i]+L[a-j:]
    S.sort()
    x=0
    while x < k-(j+i):
      if S[x]>=0:
        break
      x+=1
    ans=max(ans,sum(S)-sum(S[:x]))
    
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())
V = list(map(int, input().split()))
v = 0
for i in range(K+1):
    j = K - i
    for k in range(i+1):
        if (k == 0) and (i != 0):
            v_tmp1 = sum(V[-i:])
            v_tmp2 = [e for e in V[-i:] if e < 0]
            v_tmp2.sort()
            v_tmp = v_tmp1 - (sum(v_tmp2[:j]) if v_tmp2 else 0)
            t = 1
        elif k == i:
            v_tmp1 = sum(V[:i])
            v_tmp2 = [e for e in V[:i] if e < 0]
            v_tmp2.sort()
            v_tmp = v_tmp1 - (sum(v_tmp2[:j]) if v_tmp2 else 0)
            t = 2
        else:
            v_tmp1 = sum(V[:k] + V[(N - k):])
            v_tmp2 = [e for e in (V[:k] + V[(N - k):]) if e < 0]
            v_tmp2.sort()
            v_tmp = v_tmp1 - (sum(v_tmp2[:j]) if v_tmp2 else 0)
            t = 3
        v = max(v, v_tmp)
print(v)

N, K = map(int, input().split())
V = list(map(int, input().split()))
k = min(N, K)
v = 0
for i in range(k + 1):
    for j in range(k - i + 1):
        v_tmp = V[:i] + V[(N - j):]
        v_tmp.sort()
        for l in range(K - (i + j) + 1):
            v = max(v, sum(v_tmp[l:]))
print(v)

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()))
hand = []
ps = []
def func(V, hand, K):
    if K < 1:
        ps.append(hand)
        return
    if len(hand) > 0 and min(hand) < 0:
        hand_ = hand[:]
        hand_, min_val = handPop(hand_)
        C = func([min_val] + V, hand_, K-1)
        D = func(V + [min_val], hand_, K-1)
        A = func(V[1:], hand+[V[0]], K-1)
        B = func(V[:-1], hand+[V[-1]], K-1)
    else:
        A = func(V[1:], hand+[V[0]], K-1)
        B = func(V[:-1], hand+[V[-1]], K-1)

    
func(V, hand, K)
v_max = max([sum(x) for x in ps])
print(v_max if v_max > 0 else 0)

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for L in range(min(N, K+1)):
    for R in range(min(N-L, K-L)+1):
        js = V[:L] + V[-R:] if R > 0 else V[:L]
        t = K - L - R
        s = 0
        for i in sorted(js):
            if i < 0 and t > 0:
                s += -i
                t -= 1
        ans = max(ans, sum(js) + s)
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 sys import stdin
n, k = map(int, stdin.readline().rstrip().split())
gems = list(map(int, stdin.readline().rstrip().split()))
total = -99999999999
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1):
        if i + j <= min(n, k):
            tmp = gems[:i] + gems[n-j:]
            tmp.sort()
            total = max(total, sum(tmp))
            for l in range(min(k-i-j+1, len(tmp))):
                if tmp[l] < 0:
                    total -= tmp[l]
                else:
                    break

print(total)

from sys import stdin
n, k = map(int, stdin.readline().rstrip().split())
gems = list(map(int, stdin.readline().rstrip().split()))
total = -99999999999
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1):
        if i + j <= min(n, k):
            tmp = gems[:i] + gems[n-j:]
            tmp.sort()
            for l in range(min(k-i-j, len(tmp))):
                if tmp[l] < 0:
                    tmp[l] = 0
            total = max(total, sum(tmp))


print(total)

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()))

for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)

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

for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list = sorted(pick_list)
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)


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

for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)

Verdicts: Runtime Error

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):
from itertools import accumulate


def make_dp(vvv, n, k):
    dp = [-(10 ** 9) * (k + 1)]
    dp[0] = 0

    for i in range(min(n, k)):
        i += 1
        vv = vvv[:i]
        vv.sort(reverse=True)
        sm = sum(vv)
        dp[i] = max(dp[i], sm)
        while i < k and vv and vv[-1] < 0:
            sm -= vv.pop()
            i += 1
            dp[i] = max(dp[i], sm)

    return list(accumulate(dp, func=max))


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

acl = make_dp(vvv, n, k)
acr = make_dp(reversed(vvv), n, k)

ans = max(acl[i] + acr[k - i] for i in range(k + 1))
ans = min(ans, sum(v for v in vvv if v > 0))
print(ans)


from itertools import accumulate


def make_dp(vvv, n, k):
    dp = [-(10 ** 9)] * (k + 1)
    dp[0] = 0

    for i in range(min(n, k)):
        i += 1
        vv = vvv[:i]
        vv.sort(reverse=True)
        sm = sum(vv)
        dp[i] = max(dp[i], sm)
        while i < k and vv and vv[-1] < 0:
            sm -= vv.pop()
            i += 1
            dp[i] = max(dp[i], sm)

    return list(accumulate(dp, func=max))


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

acl = make_dp(vvv, n, k)
vvv.reverse()
acr = make_dp(vvv, n, k)
acr.reverse()

ans = max(map(sum, zip(acl, acr)))
ans = min(ans, sum(v for v in vvv if v > 0))
print(ans)


Verdicts: Runtime Error

Accepted