Problem:


Score : 400 points

Problem Statement

Snuke lives in another world, where slimes are real creatures and kept by some people.
Slimes come in N colors. Those colors are conveniently numbered 1 through N.
Snuke currently has no slime. His objective is to have slimes of all the colors together.

Snuke can perform the following two actions:

Select a color i (1≤i≤N), such that he does not currently have a slime in color i, and catch a slime in color i. This action takes him a_i seconds.

Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color i (1≤i≤N-1) will become color i+1, and the color of a slime in color N will become color 1. This action takes him x seconds.

Find the minimum time that Snuke needs to have slimes in all N colors.

Constraints

2≤N≤2,000

a_i are integers.

1≤a_i≤10^9

x is an integer.

1≤x≤10^9

Input

The input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Find the minimum time that Snuke needs to have slimes in all N colors.

Sample Input 1

2 10
1 100

Sample Output 1

12

Snuke can act as follows:

Catch a slime in color 1. This takes 1 second.

Cast the spell. The color of the slime changes: 1 → 2. This takes 10 seconds.

Catch a slime in color 1. This takes 1 second.

Sample Input 2

3 10
100 1 100

Sample Output 2

23

Snuke can act as follows:

Catch a slime in color 2. This takes 1 second.

Cast the spell. The color of the slime changes: 2 → 3. This takes 10 seconds.

Catch a slime in color 2. This takes 1 second.

Cast the soell. The color of each slime changes: 3 → 1, 2 → 3. This takes 10 seconds.

Catch a slime in color 2. This takes 1 second.

Sample Input 3

4 10
1 2 3 4

Sample Output 3

10

Snuke can act as follows:

Catch a slime in color 1. This takes 1 second.

Catch a slime in color 2. This takes 2 seconds.

Catch a slime in color 3. This takes 3 seconds.

Catch a slime in color 4. This takes 4 seconds.



Sample input:
2 10
1 100


Sample output:
12

Submission status: Wrong Answer

Solution code:
N,X = map(int, input().split())
A = list(map(int, input().split()))

mcost = [ (i, A[i]) for i in range(N)] 

from collections import defaultdict
cnt = defaultdict(int)

for i in range(1,N):
    if mcost[i-1][1] + X < mcost[i][1]:
        mcost[i] = (mcost[i-1][0], mcost[i-1][1]+X)

if mcost[N-1][1] + X < mcost[0][1]:
    mcost[0] = ( mcost[N-1][0], mcost[N-1][1]+X)

for i in range(1,N):
    if mcost[i-1][1] + X < mcost[i][1]:
        mcost[i] = (mcost[i-1][0], mcost[i-1][1]+X)

if mcost[N-1][1] + X < mcost[0][1]:
    mcost[0] = ( mcost[N-1][0], mcost[N-1][1]+X)

inf = float("inf")
maxlist = [0] * (N+1)
for idx,cst in mcost:
    cnt[idx] += 1
    if maxlist[idx] < cst:
        maxlist[idx] = cst

ans = 0
for k in cnt.keys():
    if cnt[k] == 1:
        ans += A[k]
    else:
        ans += (cnt[k]-1)*A[k] + maxlist[k]

print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int, input().split())
A = list(map(int, input().split()))

mcost = [ (i, A[i]) for i in range(N)] 

from collections import defaultdict
cnt = defaultdict(int)

for i in range(1,N):
    if mcost[i-1][1] + 10 < mcost[i][1]:
        mcost[i] = (mcost[i-1][0], mcost[i-1][1]+10)

if mcost[N-1][1] + 10 < mcost[0][1]:
    mcost[0] = ( mcost[N-1][0], mcost[N-1][1]+10)

for i in range(1,N):
    if mcost[i-1][1] + 10 < mcost[i][1]:
        mcost[i] = (mcost[i-1][0], mcost[i-1][1]+10)

if mcost[N-1][1] + 10 < mcost[0][1]:
    mcost[0] = ( mcost[N-1][0], mcost[N-1][1]+10)

inf = float("inf")
maxlist = [0] * (N+1)
for idx,cst in mcost:
    cnt[idx] += 1
    if maxlist[idx] < cst:
        maxlist[idx] = cst

ans = 0
for k in cnt.keys():
    if cnt[k] == 1:
        ans += A[k]
    else:
        ans += (cnt[k]-1)*A[k] + maxlist[k]

print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int, input().split())
A = list(map(int, input().split()))

mcost = [ (i, A[i]) for i in range(N)] # A[:]

from collections import defaultdict
cnt = defaultdict(int)
cstlst = [[] for _ in range(N)]

for i in range(1,N):
    if mcost[i-1][1] + 10 < mcost[i][1]:
        mcost[i] = (mcost[i-1][0], mcost[i-1][1]+10)

if mcost[N-1][1] + 10 < mcost[0][1]:
    mcost[0] = ( mcost[N-1][0], mcost[N-1][1]+10)

for i in range(1,N):
    if mcost[i-1][1] + 10 < mcost[i][1]:
        mcost[i] = (mcost[i-1][0], mcost[i-1][1]+10)

# lst = []
inf = float("inf")
maxlist = [0] * (N+1)
for idx,cst in mcost:
    cnt[idx] += 1
    # cstlst[idx].append(cst)
    # lst.append( (idx,cst) )
    if maxlist[idx] < cst:
        maxlist[idx] = cst

# lst = sorted(lst, lambda x: (idx, -cst) )
# from bisect import bisect_left as bll

ans = 0

# print(maxlist)
# exit(0)
for k in cnt.keys():
    if cnt[k] == 1:
        ans += A[k]
    else:
        ans += (cnt[k]-1)*A[k] + maxlist[k]

print(ans)

# print( list(zip(*mcost))[0] )
# print( list(zip(*mcost))[1] )

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, x = LI()
    A = LI()

    min_a, min_i = INF, -1
    res = 0
    for i, a in enumerate(A):
        if a < min_a:
            min_a = a
            min_i = i
        res += a
    A = A[min_i:] + A[:min_i]

    dp = [INF] + A
    for k in range(n - 1):
        tmp = 0
        for i in range(n)[::-1]:
            if dp[i + 1] > dp[i] + x:
                dp[i + 1] = dp[i]
            tmp += dp[i + 1]

        res = min(res, tmp + (k + 1) * x)

    return res


print(main())

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))

DP = a[:]
ans = sum(DP)
for i in range(n-1):
    new = [0]*n
    for j in range(n):
        new[i] = min(DP[j], DP[j-1])
    DP=new
    ans = min(ans, sum(DP) + (i+1)*x)
print(ans)

Submission status: Wrong Answer

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
for i in range(loop):
    min_catch_cost = cost[i]
    last_catch_index = i
    sum_cost = min_catch_cost
    max_magic_time = 0
    total_magic_time = 0
    temp_magic_time = 0
    for j in range(i + 1, i + loop):
        if cost[j % loop] >= magic_cost + min_catch_cost:
            sum_cost += min_catch_cost
            total_magic_time += 1
            temp_magic_time += 1
        else:
            min_catch_cost = cost[j % loop]
            last_catch_index = j
            sum_cost += cost[j % loop]
            temp_magic_time = 0
        max_magic_time = max(temp_magic_time, max_magic_time)
#         print(i, j, min_catch_cost, last_catch_index, sum_cost)
    answer = min(answer, sum_cost + (magic_cost * (max_magic_time)))
print(answer)

Submission status: Wrong Answer

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
for i in range(loop):
    min_catch_cost = cost[i]
    last_catch_index = i
    sum_cost = min_catch_cost
    max_magic_time = 0
    total_magic_time = 0
    temp_magic_time = 0
    for j in range(i + 1, i + loop):
        if cost[j % loop] >= magic_cost + min_catch_cost:
            sum_cost += magic_cost + min_catch_cost
            total_magic_time += 1
            temp_magic_time += 1
        else:
            min_catch_cost = cost[j % loop]
            last_catch_index = j
            sum_cost += cost[j % loop]
            temp_magic_time = 0
        max_magic_time = max(temp_magic_time, max_magic_time)
#         print(i, j, min_catch_cost, last_catch_index, sum_cost)
    answer = min(answer, sum_cost - (magic_cost * (total_magic_time - max_magic_time)))
print(answer)

Submission status: Wrong Answer

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
for i in range(loop):
    min_catch_cost = cost[i]
    last_catch_index = i
    sum_cost = min_catch_cost
    max_magic_time = 0
    total_magic_time = 0
    temp_magic_time = 0
    for j in range(i + 1, i + loop):
        if cost[j % loop] > magic_cost + min_catch_cost:
            sum_cost += magic_cost + min_catch_cost
            total_magic_time += 1
            temp_magic_time += 1
        else:
            min_catch_cost = cost[j % loop]
            last_catch_index = j
            sum_cost += cost[j % loop]
            temp_magic_time = 0
        max_magic_time = max(temp_magic_time, max_magic_time)
#         print(i, j, min_catch_cost, last_catch_index, sum_cost)
    answer = min(answer, sum_cost - (magic_cost * (total_magic_time - max_magic_time)))
print(answer)

Submission status: Wrong Answer

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
for i in range(loop):
    min_catch_cost = cost[i]
    last_catch_index = i
    sum_cost = min_catch_cost
    for j in range(i + 1, i + loop):
        if cost[j % loop] > magic_cost + min_catch_cost:
            sum_cost += magic_cost + min_catch_cost
        else:
            min_catch_cost = cost[j % loop]
            last_catch_index = j
            sum_cost += cost[j % loop]
#         print(i, j, min_catch_cost, last_catch_index, sum_cost)
    answer = min(answer, sum_cost)
print(answer)

Submission status: Wrong Answer

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
for i in range(loop):
    min_catch_cost = cost[i]
    last_catch_index = i
    sum_cost = min_catch_cost
    for j in range(i + 1, i + loop):
        if cost[j % loop] > (magic_cost * (j - last_catch_index)):
            sum_cost += magic_cost + min_catch_cost
        else:
            min_catch_cost = cost[j % loop]
            last_catch_index = j
            sum_cost += cost[j % loop]
#         print(i, j, min_catch_cost, last_catch_index, sum_cost)
    answer = min(answer, sum_cost)
print(answer)

Submission status: Wrong Answer

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
for i in range(loop):
    min_catch_cost = cost[i]
    last_catch_index = i
    sum_cost = 0
    for j in range(i, i + loop):
        if cost[j % loop] > (magic_cost * (j - last_catch_index)):
            sum_cost += magic_cost * (j - last_catch_index)
        else:
            min_catch_cost = cost[j % loop]
            last_catch_index = j
            sum_cost += cost[j % loop]
    answer = min(answer, sum_cost)
print(answer)

Submission status: Wrong Answer

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
for i in range(loop):
    min_catch_cost = cost[i]
    last_catch_index = i
    sum_cost = 0
    for j in range(i, i + loop):
        if cost[j % loop] > (magic_cost * (j - last_catch_index)):
            sum_cost += magic_cost * (j - last_catch_index)
        else:
            min_catch_cost = cost[j % loop]
            last_catch_index = j
            sum_cost += cost[j % loop]
    answer = min(answer, sum_cost)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
b = a
num = float('inf')
for k in range(N):
    tmp = 0
    for i in range(N):
        b[i] = min(b[i], a[i - k] + x)
        tmp += b[i]

    num = min(num, tmp)

print(num)

Submission status: Wrong Answer

Solution code:
n,x=map(int, input().split())
a=list(map(int, input().split()))
a+=a
dp=a[:]
c=0
for i in range(n*2-1):
    if dp[i+1]>dp[i]+x:
        dp[i+1]=dp[i]+x
        dp[i]-=x*c
        c+=1
    else:
        c=0
ans=sum(dp[:n])
an=ans
for i in range(n,2*n):
    ans+=dp[i]-dp[i-n]
    an=min(ans,an)
print(an)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def inpl(): return list(map(int, input().split()))
N, x = inpl()
A = inpl()
B = [a for a in A]

ans = 1e10
for i in range(N+1):
    for j in range(N):
        B[j] = min(B[j], A[(j-i)%N])
    tmp = x*i + sum(B)
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))
N, x = inpl()
A = inpl()
B = [a for a in A]

ans = 1e10
for i in range(N):
    for j in range(N):
        B[j] = min(B[j], A[(j-i)%N])
    tmp = x*i + sum(B)
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a_list = list(map(int, input().split()))

change_cost = []
for i in range(N):
    cost = float("inf")
    time = 0
    for j in range(N):
        if i == j:
            continue
        elif i < j:
            if cost > ((N - 1) - j + i + 1) * x + a_list[j]:
                cost = ((N - 1) - j + i + 1) * x + a_list[j]
                time = (N - 1) - j + i + 1
        else:
            if cost > (i - j) * x + a_list[j]:
                cost = (i - j) * x + a_list[j]
                time = i - j
    change_cost.append((cost, time))

ans = 0
max_time = 0
amount_time = 0
for i in range(N):
    a = a_list[i]
    c, t = change_cost[i]
    if c >= a:
        ans += a
    else:
        ans += c
        max_time = max(max_time, t)
        amount_time += t
print(ans - (amount_time - max_time) * x)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
B=[[A[i],i] for i in range(N)]
ans=sum(A)
for t in range(1,N):
    #print(B)
    for i in range(N):
        if B[i][0]+(i-B[i][1])*X>A[i-t]+t*X:
            B[i][0]=A[i-t]
            B[i][1]=i-t
    #print(sum(B)+t*X)
    num=0
    for b,c in B:
        num+=b
    ans=min(ans,num+t*X)
#print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
B=deepcopy(A)
ans=sum(A)
for t in range(1,N):
    #print(B)
    for i in range(N):
        if B[i]>A[i-t]+t*X:
            B[i]=A[i-t]
    ans=min(ans,sum(B)+t*X)
#print(B)
print(ans)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
B=A
ans=sum(A)
for t in range(1,N):
    for i in range(N):
        if B[i]>A[i-t]+t*X:
            B[i]=A[i-t]
    ans=min(ans,sum(B)+t*X)
print(ans)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
t=-1
for i in range(N):
    time=-1
    al=-1
    x=10**10
    for j in range(i+1):
        if x>A[i-j]+X*(j):
            x=A[i-j]+X*(j)
            time=j
            al=A[i-j]
    for j in range(N-i-1,0,-1):
        if x>A[i+j]+X*(N-j):
            x=A[i+j]+X*(N-j)
            al=A[i+j]
            time=N-j
    #print(al,j)
    ans+=al
    t=max(time,t)
print(ans+X*t)

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
ans=0
t=-1
for i in range(N):
    time=-1
    al=-1
    x=10**10
    for j in range(i+1):
        if x>A[i-j]+X*(j):
            x=A[i-j]+X*(j)
            time=j
            al=A[i-j]
    for j in range(1,N-i):
        if x>A[i+j]+X*(N-j):
            x=A[i+j]+X*(N-j)
            al=A[i+j]
            time=N-j
    ans+=al
    t=max(time,t)
print(ans+X*t)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))	

p = 1
r = 0
for i in range(1,n):
    if a[i] > a[i-1] + p*x:
        p += 1
        a[i] = a[i-1]
    else:
        r = max(r,p-1)
        p = 1

if a[0] > a[n-1]+p*x:
    p += 1
    a[0] = a[n-1]
else:
    r  = max(r,p-1)
    p = 1


for i in range(1,n):
    if a[i] > a[i-1] + p*x:
        p += 1
        a[i] = a[i-1]
    else:
        r = max(r,p-1)
        p = 1

if a[0] > a[n-1]+p*x:
    p += 1
    a[0] = a[n-1]
else:
    r  = max(r,p-1)
    p = 1



print(sum(a)+r*x)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = [int(a) for a in input().split()]
minA = min(A)
lim = minA + x
Ans = 0
for i in range(N):
    Ans += min(A[i], lim)
print(Ans)

Submission status: Wrong Answer

Solution code:

N,x = list(map(int,input().split()))

a = list(map(int,input().split()))

dp = [10**27 for i in range(N)]
for i in range(N):
    for j in range(N):
        if i<=j:
            d=j-i
        else:
            d=N-i+j
        dp[j]=min(a[i]+d*x,dp[j])

print(sum(dp))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
MIN = sum(a)
ans = MIN
tori = a + [0]
tori.pop()
for i in range(1,n):
  for j in range(n):
    ido = i+j
    if ido >= n:
      ido-=n
    if tori[j] > a[ido]:
      tori[j] = a[ido]
      ans -= (tori[j] - a[ido])
  MIN = min(ans + i*x,MIN)
print(MIN)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
MIN = sum(a)
tori = a + [0]
tori.pop()
for i in range(1,n):
  for j in range(n):
    ido = i+j
    if ido >= n:
      ido-=n
    tori[j] = min(a[ido],tori[j])
  MIN = sum(tori) + i*x
print(MIN)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,x = li()
a = list(li())
a = a+a

mins = [-1]*n
idxs = [-1]*n

for i in range(n,2*n):
    lst = [a[i-j] + j*x for j in range(n)]
    mins[i-n] = min(lst)
    idxs[i-n] = lst.index(mins[i-n])
    
ans = x*max(idxs)
idxs = idxs+idxs
first_zero = idxs.index(0)
temp = 0
for ai, idx in zip(a[first_zero:first_zero+n],idxs[first_zero:first_zero+n]):
    if idx == 0:
        temp = ai
        ans += temp
        
    else:
        ans += temp
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,x = li()
a = list(li())
a = a+a

mins = [-1]*n
idxs = [-1]*n

for i in range(n,2*n):
    lst = [a[i-j] + j*x for j in range(n)]
    mins[i-n] = min(lst)
    idxs[i-n] = lst.index(mins[i-n])
    
ans = x*max(idxs)
idxs = idxs+idxs
first_zero = idxs.index(0)
for ai, idx in zip(a[first_zero:first_zero+n],idxs[first_zero:first_zero+n]):
    if idx == 0:
        temp = ai
        ans += temp
        
    else:
        ans += temp
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,x = li()
a = list(li())
a = a+a

mins = [-1]*n
idxs = [-1]*n

for i in range(n,2*n):
    lst = [a[i-j] + j*x for j in range(n)]
    mins[i-n] = min(lst)
    idxs[i-n] = lst.index(mins[i-n])
    
ans = x*max(idxs)
idxs = idxs+idxs
first_zero = idxs.index(0)
for ai, idx in zip(a[first_zero:first_zero+n],idxs[first_zero:first_zero+n]):
    if idx == 0:
        temp = ai
        
    else:
        pass
    
    ans += temp
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
A = list(map(int,input().split()))

ans = sum(A)
costs = A[:]
for i in range(1,N):
    cost = i*X
    if cost >= ans: break
    for j in range(N):
        costs[j] = min(costs[j], costs[(j-i)%N])
        cost += costs[j]
    ans = min(ans, cost)

print(ans)

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s = 0

for i in range(N):
	lis = []
	for j in range(N):
		lis.append(a[i - j] + j * x)
	s += min(lis)

print(s)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, x = inpl()
A = inpl()

min_index = A.index(min(A))
B = A[min_index:] + A[:min_index]

cost = [B[i] for i in range(N)]

ans = INF
for magic in range(N):
    for i in range(N):
        if i - magic >= 0:
            cost[i] = min(cost[i], B[i - magic])

    ans = min(ans, sum(B) + x * magic)

print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())

a = list(map(int, input().split()))

temp = 0
check = 0
for i in range(1, n):
    if a[i] <= a[i - 1] + x:
        check = 1
        temp = i
        break

if check == 1:
    a = a[temp:] + a[:temp]

check = 1
max_check = 0
for i in range(1, n):
    if a[i] >= a[i - check] + x:
        a[i] = a[i - check]
        max_check = max(check, max_check)
        check += 1
    else:
        check = 1

print(sum(a) + max_check * x)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())

a = list(map(int, input().split()))

temp = 0
check = 0
for i in range(1, n):
    if a[i] <= a[i - 1] + x:
        check = 1
        temp = i
        break

if check == 1:
    a = a[temp:] + a[:temp]

check = 1
for i in range(1, n):
    if a[i] >= a[i - check] + x:
        a[i] = a[i - check] + x
        check += 1
    else:
        check = 1

print(sum(a))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())

a = list(map(int, input().split()))

temp = 0
check = 0
for i in range(1, n):
    if a[i] <= a[i - 1] + x:
        check = 1
        temp = i
        break

if check == 1:
    a = a[temp:] + a[:temp]

check = 1
for i in range(1, n):
    if a[i] > a[i - check] + x:
        a[i] = a[i - check] + x
        check += 1
    else:
        check = 1

print(sum(a))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a += a
mah = [10000000000]*n
ans = float("inf")
for i in range(1, n+1):
    t = 0
    for j in range(n):
        if mah[j] > a[j + i]:
            mah[j] = a[j+i]
        t += mah[j]
    ans = min(ans, t+10*(i-1))
print(ans)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
m = min(a)
magic = x+m
cnt=0
for i in a:
    if i<magic:
        cnt+=i
    else:
        cnt+=magic
print(cnt)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))

b = list(map(int,input().split()))

c = min(b)
su = 0
for i in range(a[0]):
    if b[i] >= a[1] + c:
        su += a[1] + c
    else:
        su += b[i]

print(su)

Submission status: Wrong Answer

Solution code:
f = lambda: list(map(int,input().split()))
n,x = f()
a = f()
w = 0
ans = 0
for k in range(n):
    b = [a[i] + x*(k-i) for i in range(k+1)] + [a[i] + x*(n+k-i) for i in range(k+1,n)]
    m = b.index(min(b))
    ans += a[m]
    if m>k:
        m = n+k-m
    else:
        m = k-m
    w = max(w, m)
print(ans + w*x)

Submission status: Wrong Answer

Solution code:
f = lambda: list(map(int,input().split()))

n,x = f()
a = f()
w = 0
ans = 0
for k in range(n):
    b = [a[i] + x*(k-i) for i in range(k+1)] + [a[i] + x*(n+k-i) for i in range(k+1,n)]
    print(b)
    m = b.index(min(b))
    ans += a[m]
    if m>k:
        m = n+k-m
    else:
        m = k-m
    print(m)
    w = max(w, m)
print(ans + w*x)

Submission status: Wrong Answer

Solution code:
f = lambda: list(map(int,input().split()))
f_ = lambda: [int(x)-1 for x in input().split()]

n,x = f()
a = f()
w = 0
ans = 0
for k in range(n):
    b = [a[i] + x*(k-i) for i in range(k+1)] + [a[i] + x*(n-k+i-2) for i in range(k+1,n)]
    m = b.index(min(b))
    ans += a[m]
    if m>k:
        m = n-k+m-2
    else:
        m = k-m
    w = max(w, m)
print(ans + w*x)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, A):

    ans = sys.maxsize
    mc = [(sys.maxsize, -1)] * N
    for k in range(N):
        ac = 0
        for i in range(N):
            mc[i] = min(mc[i], (A[i-k] + k*X, k), key=lambda x: x[0])
            ac += A[i-mc[i][1]]
        ac += k*X
        ans = min(ans, ac)

    return ans


def main():
    N, X = read_int_n()
    A = read_int_n()
    print(slv(N, X, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, A):

    ans = sys.maxsize
    mc = [(sys.maxsize, -1)] * N
    for k in range(N):
        r = 0
        ac = 0
        for i in range(N):
            mc[i] = min(mc[i], (A[i-k] + k*X, k), key=lambda x: x[0])
            r = max(r, mc[i][1])
            ac += A[i-mc[i][1]]
        ac += r*X
        ans = min(ans, ac)

    return ans


def main():
    N, X = read_int_n()
    A = read_int_n()
    print(slv(N, X, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, A):

    r = 0
    for i in range(N):
        c = (sys.maxsize, -1)
        for j in range(N):
            c = min(c, (A[i-j] + j*X, j), key=lambda x: x[0])
        r = max(r, c[1])

    ans = 0
    for i in range(N):
        c = (sys.maxsize, -1)
        for j in range(r+1):
            c = min(c, (A[i-j], j), key=lambda x: x[0])
        ans += A[i-c[1]]

    ans += r*X
    return ans


def main():
    N, X = read_int_n()
    A = read_int_n()
    print(slv(N, X, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, A):
    ans = 0
    r = 0
    for i in range(N):
        j = 0
        c = (sys.maxsize, -1)
        for j in range(N):
            c = min(c, (A[i-j] + j*X, j), key=lambda x: x[0])
        ans += A[i-c[1]]
        r = max(r, c[1])

    ans += r*X
    return ans


def main():
    N, X = read_int_n()
    A = read_int_n()
    print(slv(N, X, A))


if __name__ == '__main__':
    main()