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

Submission attempts (in order):
import heapq as hq

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

ans=0
for i in range(1,min(N,K)+1): 
    for j in range(i+1):
        A=[]
        hq.heapify(A) 
        for k in range(j):
            hq.heappush(A,V[k])
        for k in range(i-j):
            hq.heappush(A,V[n-k-1])
        p=min(i,K-i) 
        while p>0:
            if A[0]<0:
                hq.heappop(A)
                p-=1
            else:
                break
        ans=max(sum(A),ans)
print(ans)

import heapq as hq

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

ans=0
for i in range(1,min(N,K)+1): 
    for j in range(i+1):
        A=[]
        hq.heapify(A) 
        for k in range(j):
            hq.heappush(A,V[k])
        for k in range(i-j):
            hq.heappush(A,V[N-k-1])
        p=min(i,K-i) 
        while p>0:
            if A[0]<0:
                hq.heappop(A)
                p-=1
            else:
                break
        ans=max(sum(A),ans)
print(ans)

Verdicts: Runtime Error

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

Submission attempts (in order):
import sys
sys.setrecursionlimit(100000)

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


ans = 0
for i in range(K+1):
  hand = V[:i]
  for j in range(K-i+1):
    if j != 0:
      x = hand + V[max(K-j, i):]
    else:
      x = hand
    rest = K - i - j
    summ = sum(v for i, v in enumerate(sorted(x)) if i >= rest or v > 0)
    ans = max(ans, summ)
    
print(ans)



import sys
sys.setrecursionlimit(100000)

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


ans = 0
for i in range(K+1):
  hand = V[:i]
  for j in range(K-i+1):
    if j != 0:
      x = hand + V[max(N-j, i):]
    else:
      x = hand
    rest = K - i - j
    summ = sum(v for i, v in enumerate(sorted(x)) if i >= rest or v > 0)
    ans = max(ans, summ)
    
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 bisect
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0
for pull_num in range(K+1):
  	if pull_num > N:
        continue
    push_num = K - pull_num
    #print('pull_num:{}'.format(pull_num))
    for left_num in range(pull_num+1):
        right_num = pull_num - left_num
        #print('left_num:{} right_num:{}'.format(left_num, right_num))
        left_D = D[:left_num];  right_D = D[N-right_num:]
        #print('left_D:{} right_D:{}'.format(left_D, right_D))
        temochi = left_D + right_D
        temochi.sort()
        
        index = bisect.bisect_left(temochi, 0)
        #print('index:{}'.format(index))
        #print('push_num:{}'.format(push_num))
        if push_num >= index:
            ans = max(ans, sum(temochi[index:]))
        else:
            ans = max(ans, sum(temochi[push_num:]))
print(ans)

import bisect
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0
for pull_num in range(K+1):
    if pull_num > N:
        continue
    push_num = K - pull_num
    for left_num in range(pull_num+1):
        right_num = pull_num - left_num
        left_D = D[:left_num];  right_D = D[N-right_num:]
        temochi = left_D + right_D
        temochi.sort()
        index = bisect.bisect_left(temochi, 0)
        if push_num >= index:
            ans = max(ans, sum(temochi[index:]))
        else:
            ans = max(ans, sum(temochi[push_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):
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
V = list(map(int,input().split()))

D = []
ans = 0

for i in range(K+1):
    for j in range(K-i+1):
        if i + j > N:
            break
        D.append(V[:i]+V[N-j:])

for d in D:
    for x in range(K-len(d)):
        if d==[]:
            break
        elif min(d)<0:
            d.pop(d.index(min(d)))

        elif min(d)>0:
            break
        
        if d!=[]:
            s = sum(d)
            if s>0 and s>ans:
                ans = s

print(s)

import sys
input = sys.stdin.readline
N,K = map(int,input().split())
V = list(map(int,input().split()))
D = []
ans = 0
for i in range(K+1):
    for j in range(K-i+1):
        if i + j > N:
            break
        D.append(V[:i]+V[N-j:])
for d in D:
    for x in range(K-len(d)):
        if d==[]:
            break
        elif min(d)<0:
            d.pop(d.index(min(d)))

        elif min(d)>0:
            break        
    if d!=[]:
        s = sum(d)
        if s>0 and s>ans:
            ans = 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):
import heapq 
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K) 
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        A1 = A[:i] 
        A3 = A[N-j:] 
        new_A = A1+A3
        new_A.sort()
        h = K - len(new_A)
        while h >0 and new_A:
            if new_A[-1] > 0:
                break
            else:
                new_A.pop()
                h-=1
        M = max(M,sum(new_A))
print(M)

import heapq 
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K) 
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        A1 = A[:i] 
        A3 = A[N-j:] 
        new_A = A1+A3
        new_A.sort()
        h = K - len(new_A)
        while h >0:
            if new_A[-1] > 0:
                break
            else:
                new_A.pop()
                h-=1
        M = max(M,sum(new_A))
print(M)

N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K)
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        v=A[:i]+A[N-j:]
        v.sort()
        v=v[::-1]
        h=K-len(v)
        while h >0 and v:
            if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
        M=max(M,sum(v))
print(M)

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

ans = 0
for i in range(n):
    for j in range(n):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            print(g, min(k-i-j, i+j))
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:]))

print(ans)


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

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i + j <= k and i + j <= n:
            g = v[:i] + v[n-j:]
            g.sort()
            for l in range(min(k-i-j, i+j)+1):
                ans = max(ans, sum(g[l:]))

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 collections import deque

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
O = min(N, K)
for i in range(O+1):
    for j in range(O-i+1):
        if i + j > O:
            break
        DV = deque(V)
        S = 0
        nums = []
        for _ in range(i):
            nums.append(DV.popleft())
        for _ in range(j):
            nums.append(DV.pop())
        nums.sort()
        for n in range(min(K-i-j, len(nums))):
            if nums[n] >= 0:
                break
            del nums[n]
        ans = max(ans, sum(nums))
print(ans)

from collections import deque

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
O = min(N, K)
for i in range(O+1):
    for j in range(O-i+1):
        if i + j > O:
            break
        DV = deque(V)
        S = 0
        nums = []
        for _ in range(i):
            nums.append(DV.popleft())
        for _ in range(j):
            nums.append(DV.pop())
        nums.sort()
        print(nums)
        d = 0
        for k, n in enumerate(nums):
            if d == K - i - j:
                break
            if n < 0:
                del nums[k]
                d += 1
            else:
                break
        ans = max(ans, sum(nums))
print(ans)

from collections import deque

N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
O = min(N, K)
for i in range(O+1):
    for j in range(O-i+1):
        if i + j > O:
            break
        DV = deque(V)
        S = 0
        nums = []
        for _ in range(i):
            nums.append(DV.popleft())
        for _ in range(j):
            nums.append(DV.pop())
        nums.sort()
        S = sum(nums)
        for n in range(min(K-i-j, len(nums))):
            if nums[n] >= 0:
                break
            S -= nums[n]
        ans = max(ans, S)
print(ans)

Verdicts: Runtime Error

Wrong Answer

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

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

def calc(l, r, d):
    hold = V[:l] + V[r:]
    hold.sort()
    return sum(hold[d:]) 

ret = 0
K = min(N, K)
for l in range(K+1):
    for r in range(K+1-l):
        for d in range(K+1-l-r):
            ret = max(ret, calc(l, r, d))
print(ret)

N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0
K = min(N, K)
for l in range(K+1):
    for r in range(K+1-l):
        hold = V[:l] + U[r:]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

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

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + V[N-r:]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)

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 heapq
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for k in range(K+1):
    for i in range(k+1):
        tmp = 0
        tmp2 = []
        heapq.heapify(tmp2)

        for j in range(k-i):
            tmp += V[j]
            if V[j] < 0:
                heapq.heappush(tmp2, V[j])
        for j in range(i):
            tmp += V[j]
            if V[N-1-j] < 0:

                heapq.heappush(tmp2, V[j])

        for j in range(min(k, K-k)):
            tmp -= heapq.heappop(tmp2)
        ans = max(tmp, ans)


print(ans)


import heapq
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for k in range(min(K+1, N+1)):
    for i in range(k+1):
        tmp = 0
        tmp2 = []
        heapq.heapify(tmp2)

        for j in range(k-i):
            tmp += V[j]
            if V[j] < 0:
                heapq.heappush(tmp2, V[j])
        for j in range(i):
            tmp += V[N-1-j]
            if V[N-1-j] < 0:

                heapq.heappush(tmp2, V[N-1-j])

        for j in range(min(k, K-k)):
            if len(tmp2) == 0:
                break
            tmp -= heapq.heappop(tmp2)
        ans = max(tmp, ans)


print(ans)


Verdicts: Runtime Error

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

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

left = np.cumsum([0] + v)
right = np.cumsum([0] + v[::-1])

results = []
for backn in range(k + 1):
    at = k - backn

    t = min(n, at)
    # print('----', backn, t)
    for shift in range(t + 1):
        p = v[:t - shift] + v[n - shift:]
        # print(v[:t - shift], v[n - shift:])
        p.sort()
        value = sum(p[backn + 1:])
        results.append(value)
print(max(results + [0]))


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

left = np.cumsum([0] + v)
right = np.cumsum([0] + v[::-1])

results = []
for backn in range(k + 1):
    at = k - backn

    t = min(n, at)
    # print('----', backn, t)
    for shift in range(t + 1):
        p = v[:t - shift] + v[n - shift:]
        # print(v[:t - shift], v[n - shift:])
        p.sort()
        value = sum(p[backn:])
        results.append(value)
print(max(max(results)), 0)


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

results = []
for backn in range(k + 1):
    at = k - backn

    t = min(n, at)
    for i in range(0, t + 1):
        for shift in range(i + 1):
            p = v[:i - shift] + v[n - shift:]
            p.sort()
            value = sum(p[backn:])
            results.append(value)
print(max(results))


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):
a,k=map(int,input().split())
L=list(map(int,input().split()))
ans=0

for i in range(min(k,n)+1):
  for j in range(min(k,n)-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)


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

left = K
right = K - left

ans = -pow(10, 9)
while left < 0:
  all_get = V[:left] + V[::-1][:right]
  all_get.sort(reverse=True)
  num = 0
  while True:
    if num >= K - (left + right) or all_get[-1] >= 0:
      break
    all_get.pop(-1)
  now = sum(all_get)
  ans = max(ans, now)
  left -= 1
  right += 1
print(ans)

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

ans = -pow(10, 9)
for left in range(0, K + 1):
  for right in range(0, K - left + 1):
    if left + right < N:
      all_get = V[:left] + V[::-1][:right]
    else:
      all_get = V[:]
    all_get.sort(reverse=True)
    num = 0
    while True:
      if num >= K - (left + right) or len(all_get) == 0:
        break
      if all_get[-1] >= 0:
        break
      all_get.pop(-1)
      num += 1
    now = sum(all_get)
    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):
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        if left + right > n:
            break
        rest = k - left - right
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus)

print(ans)

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

ans = 0
for left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        rest = k - left - right
        if left + right > n or rest < 0:
            break
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus)

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 = map(int,input().split())

ans = 0

for l in range(n):
    for r in range(n-l+1):
        if l+r >k:
            break
        nv = v[:l] + v[n-r:]
        nv.sort()
        for i in range(k-l-r):
            if not nv or nv[0] >= 0:
                break
            nv.pop(0)
        ans = max(ans,sum(nv))
print(ans)


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

ans = 0

for l in range(n):
    for r in range(n-l+1):
        if l+r >k:
            break
        nv = v[:l] + v[n-r:]
        nv.sort()
        for i in range(k-l-r):
            if not nv or nv[0] >= 0:
                break
            nv.pop(0)
        ans = max(ans,sum(nv))
print(ans)


Verdicts: Runtime Error

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

Submission attempts (in order):
from collections import deque

N, K =map(int, input().split())
V=list(map(int, input().split()))
Vd = deque(V)
score = 0

for a in range(min(K,N)+1):
  for b in range(min(K-a+1,N-a+1)):
    print([a,b])
    hou = []
    Vd = deque(V)
    for _ in range(a):
      hou.append(Vd.popleft())
    for _ in range(b):
      hou.append(Vd.pop())
    hou.sort()
    for _ in range(K-a-b):
      if hou:
        if hou[0]>0:
          break
        hou.pop(0)
    score = max(score,sum(hou))
    
print(score)

from collections import deque

N, K =map(int, input().split())
V=list(map(int, input().split()))
Vd = deque(V)
score = 0

for a in range(min(K,N)+1):
  for b in range(min(K-a+1,N-a+1)):
    hou = []
    Vd = deque(V)
    for _ in range(a):
      hou.append(Vd.popleft())
    for _ in range(b):
      hou.append(Vd.pop())
    hou.sort()
    for _ in range(K-a-b):
      if hou:
        if hou[0]>0:
          break
        hou.pop(0)
    score = max(score,sum(hou))
    
print(score)

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()))
ansl = []
p = 1
for i in range(min(k+1,n+1)):
    for j in range(i+1):
        v1 = v[0:j]
        v2 = v[n-(i-j):n]    
        v1.extend(v2)
        v1.sort()
        for x in range(k-i-2):
            if len(v1) != 0:
                del v1[0]
        if len(v1) != 0:
            ansl.append(sum(v1))
        elif len(v1) == 0 and k%2 == 0:
            ansl.append(0)
ans = max(ansl)
print(ans)

n,k = map(int,input().split())
v = list(map(int,input().split()))
ansl = []
for i in range(min(k+1,n+1)):
    for j in range(i+1):
        v1 = v[0:j]
        v2 = v[n-(i-j):n]    
        v1.extend(v2)
        v1.sort()
        for x in range(k-i):
            if len(v1) != 0 and v1[0] < 0:
                del v1[0]
            else:
                break
        if len(v1) != 0:
            ansl.append(sum(v1))
        else:
            ansl.append(0)
ans = max(ansl)
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 functools import lru_cache

N,K=[int(i) for i in input().split(" ")]
V=[int(i) for i in input().split(" ")]

@lru_cache()
def value(V,k,hands):
    if k==0:
        return sum(hands)
    else:
        retval=sum(hands)
        try:
            retval=max(value(V[1::],k-1,sorted(hands+[V[0]])),retval)
        except:
            pass
        try:
            p2=value(V[:-1:],k-1,sorted(hands+[V[-1]]))
            retval=max(retval,p2)
        except:
            pass
        try:
            p3=value(V+[hands[0]],k-1,hands[1::])
            retval=max(p3,retval)
        except:
            pass
        try:
            p4=value([hands[0]]+V,k-1,hands[1::])
            retval=max(p4,retval)
        except:
            pass
        return retval

print(value(V,K,[]))


from functools import lru_cache
import numpy as np

N,K=[int(i) for i in input().split(" ")]
V=[int(i) for i in input().split(" ")]

retval=0
for left in range(max(N+1,K+1)):
    for right in range(min(N-left+1,K-left+1)):
        modoseru=K-(left+right)
        temoto=np.asarray(sorted(V[:left:]+V[N-right::]))
        modosu=min(np.sum(temoto<0),modoseru)
        retval=max(sum(temoto[modosu::]),retval)

print(retval)


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_rev = list(reversed(V))
val = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(N):
        val[i + 1][j] = val[i][j] + V[i]
        val[i][j + 1] = val[i][j] + V_rev[j]

val[N][N] = val[N][N - 1] + V_rev[N - 1]

ans = 0
for l in range(N + 1):
    for r in range(N + 1):
        num = l + r
        if num > K or num > N:
            continue
        rm = []
        can = (K - num)
        for li in range(l):
            if V[li] < 0:
                rm.append(V[li])
        for ri in range(r):
            if V_rev[ri] < 0:
                rm.append(V_rev[ri])

        rm.sort()
        print(l, r, val[l][r], sum(rm[:can]))
        ans = max(ans, val[l][r] - sum(rm[:can]))

print(ans)

N, K = map(int, input().split(" "))
V = list(map(int, input().split(" ")))
V_rev = list(reversed(V))
val = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(N):
        val[i + 1][j] = val[i][j] + V[i]
        val[i][j + 1] = val[i][j] + V_rev[j]

val[N][N] = val[N][N - 1] + V_rev[N - 1]

ans = 0
for l in range(N + 1):
    for r in range(N + 1):
        num = l + r
        if num > K or num > N:
            continue
        rm = []
        can = (K - num)
        for li in range(l):
            if V[li] < 0:
                rm.append(V[li])
        for ri in range(r):
            if V_rev[ri] < 0:
                rm.append(V_rev[ri])

        rm.sort()
        ans = max(ans, val[l][r] - sum(rm[:can]))

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())
xs=[0]+list(map(int,input().split()))
from itertools import accumulate
As=list(accumulate(xs))
r = 0
for i in range(k+1):
    for j in range(i, k+1):
        x = i, j-i, k-j
        m = As[i] + As[n] - As[n-j+i]
        
#        if m > r:
#            print(x, m, m1)
        r = max(r, m)
print(r)


n,k=map(int,input().split())
xs=[0]+list(map(int,input().split()))
from itertools import accumulate
As=list(accumulate(xs))
r = 0
for i in range(k+1):
    for j in range(i, k+1):
        x = i, j-i, k-j
#        m1 = As[i] + As[n] - As[n-j+i]
        m = sum(sorted(z for z in (xs[:i]+xs[n-j+i+1:]) if z < 0)[:k-j])
#        if m > r:
#            print(x, m, m1)
        r = max(r, m)
print(r)


n,k=map(int,input().split())
xs=[0]+list(map(int,input().split()))
from itertools import accumulate
As=list(accumulate(xs))
r = 0
for i in range(k+1):
    for j in range(i, k+1):
        x = i, j-i, k-j
        if j > n:
            continue
        m1 = As[i] + As[n] - As[n-j+i]
        m = m1 - sum(sorted(z for z in (xs[:i]+xs[n-j+i+1:]) if z < 0)[:k-j])
#        if m > r:
#            print(x, m, m1)
        r = max(r, m)
print(r)


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):
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
input = sys.stdin.readline
 










def main():
	N, K = map(int, input().split(" "))
	#N = int(input())
	#S = input()
	V = input().split(" ")
	V = [int(s) for s in V]

	ptn = []
	for i in range(K):
		tmp = K - i
		ptn.append((i, tmp))

	ans = 0
	for i in ptn:
		L, R = i
		tmp = 0
		for i in range(L):
			tmp += V[i]
		for i in range(R):
			tmp += V[-i-1]
		
		if tmp > ans:
			ans = tmp

	print(ans)

if __name__ == "__main__":
	main()

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
	
def main():
	N, K = map(int, input().split(" "))
	V = list(map(int, input().split(" ")))
	
	V_tmp = copy.deepcopy(V)
	ans = 0
	for L in range(K+1):
		for R in range((K+1)-L):
			V = copy.deepcopy(V_tmp)
			gets = []
			tmp = 0
			
			for i in range(L):
				if len(V) > 0:
					tmptmp = V.pop(0)
					tmp += tmptmp
					if tmptmp < 0:
						gets.append(tmptmp)
					
			for i in range(R):
				if len(V) > 0:
					tmptmp = V.pop(-1)
					tmp += tmptmp
					if tmptmp < 0:
						gets.append(tmptmp)
					
			#print(gets)
			for i in range(K-L-R):
				if len(gets) == 0:
					break
				gets.sort()
				tmp = tmp + (-1 * gets.pop(0))
				
			if tmp > ans:
				ans = tmp
				
	print(ans)
	
	
	
if __name__ == "__main__":
	main()


Verdicts: Runtime Error

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

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

def query(l, r):
    if (l+r > min(N, K)):
        return 0
    rest = K-l-r
    lst = V[:l] + (V[-r:] if r is not 0 else [])
    print(l, r, len(lst))
    lst.sort()
    print([x for i, x in enumerate(lst) if x > 0 or i >= rest])
    return sum([x for i, x in enumerate(lst) if x > 0 or i >= rest])

ans = 0
for l in range(N):
    for r in range(N):
        ans = max(ans, query(l, r))
print(ans)

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

def query(l, r):
    if (l+r > min(N, K)):
        return -1
    rest = K-l-r
    lst = V[:l] + V[N-r+1:]
    lst.sort()
    return sum([x for i, x in enumerate(lst) if x > 0 or i >= rest])

ans = 0
for l in range(N):
    for r in range(N):
        ans = max(ans, query(l, r))
print(ans)

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

def query(l, r):
    if (l+r > min(N, K)):
        return 0
    rest = K-l-r
    lst = V[:l] + V[N-r+1:]
    lst.sort()
    print(l, r, lst, sum([x for i, x in enumerate(lst) if x > 0 or i >= rest]))
    return sum([x for i, x in enumerate(lst) if x > 0 or i >= rest])

ans = 0
for l in range(N):
    for r in range(N):
        ans = max(ans, query(l, r))
print(ans)

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

def query(l, r):
    if (l+r > K):
        return 0
    rest = K-l-r
    lst = V[:l] + V[N-r:]
    lst.sort()
    return sum([x for i, x in enumerate(lst) if x > 0 or i >= rest])

ans = 0
for l in range(N+1):
    for r in range(N+1-l):
        ans = max(ans, query(l, r))
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted