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:
import sys

rl = sys.stdin.readline


class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, _k, x):
        k = _k + self.N0 - 1
        self.data[k] = x
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left, right):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        
        while L < R:
            if L & 1:
                res = self.segfunc(res, self.data[L - 1])
                L += 1
            if R & 1:
                R -= 1
                res = self.segfunc(res, self.data[R - 1])
            L = (L - 1) // 2
            R = (R - 1) // 2
        
        return res


def solve():
    N, x = map(int, rl().split())
    a = list(map(int, rl().split()))
    
    seg_tree = SegmentTree(a, min, 10 ** 15)
    ans = 10 ** 15
    for i in range(N):
        get_cost = 0
        for j in range(N):
            if i <= j:
                get_cost += seg_tree.query(j - i, j + 1)
            else:
                get_cost += min(seg_tree.query(0, j + 1), seg_tree.query(N - i + j, N))
        ans = min(ans, i * x + get_cost)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as acc
N, x, *A = map(int, open(0).read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**10
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)

Submission status: Wrong Answer

Solution code:
N, x, *A = map(int, open(0).read().split())
mc = 0
dp = [[(10**10,0)]*N for i in range(N)]
for i in range(N):
  dp[i][0] = (A[i],0)
  for j in range(1,N):
    h = (i-j)%N
    if j*x+A[h]<dp[i][j-1][0]:
      dp[i][j] = (j*x+A[h],j)
    else:
      dp[i][j] = dp[i][j-1]
ans = 10**30
for i in range(N):
  s = i*x
  for j in range(N):
    s += dp[j][i][0]-dp[j][i][1]*x
  ans = min(ans,s)
print(ans)

Submission status: Wrong Answer

Solution code:
N, x, *A = map(int, open(0).read().split())
mc = 0
done = [0]*N
dp = [[(10**10,0)]*(N-1) for i in range(N)]
for i in range(N):
  dp[i][0] = (A[i],0)
  for j in range(1,N-1):
    h = (i-j)%N
    if j*x+A[h]<dp[i][j-1][0]:
      dp[i][j] = (j*x+A[h],j)
    else:
      dp[i][j] = dp[i][j-1]
ans = 10**30
for i in range(N-1):
  s = i*x
  for j in range(N):
    s += dp[j][i][0]-dp[j][i][1]*x
  ans = min(ans,s)
print(ans)

Submission status: Wrong Answer

Solution code:
N, x, *A = map(int, open(0).read().split())
mc = 0
done = [0]*N
for i in range(N):
  m = 10**20
  for j in range(N):
    cnt = (i-j)%N
    n = cnt*x+A[j]
    if n<m:
      m = n
      k = j
      c = cnt
  if mc<c:
    mc = c
  done[k] += 1
ans = sum(a*c for a,c in zip(A,done))+mc*x
print(ans)

Submission status: Wrong Answer

Solution code:
N, x, *A = map(int, open(0).read().split())
mc = 0
done = [0]*(N+1)
for i in range(N):
  m = 10**20
  for j in range(N):
    cnt = (j-i)%N
    n = cnt*x+A[j]
    if n<m:
      m = n
      k = j
      c = cnt
  if mc<c:
    mc = c
  done[k] += 1

ans = sum(a*c for a,c in zip(A,done))+mc*x
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
cnt=0
while cnt!=n:
  if cnt==0:
    index=a.index(min(a))
    ans+=min(a)
    prev=index
    first=index
    cnt+=1
  else:
    if a[first]+x<a[0 if prev+1>=n else prev+1]:
      ans+=(x+a[first])
    else:
      ans+=a[0 if prev+1>=n else prev+1]
    prev=0 if prev+1>=n else prev+1
    cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
A = list(map(int,input().split()))
amin = 10**9+1
ind = -1
for i in range(N):
    if A[i]<amin:
        ind = i
        amin = A[i]
B = [0 for _ in range(N)]
cnt = 0
for i in range(N):
    if A[i]<=amin+x:
        B[i] = 1
        cnt += A[i]
while True:
    if B[ind]==0:
        B[ind] = 1
        cnt += amin
    else:
        flg = 0
        for i in range(ind-1,ind-N,-1):
            i = i%N
            if B[i]==0:
                j = i
                flg = 1
                break
        if flg==0:break
        if amin+((ind-j)%N)*x<A[j]:
            C = [0 for _ in range(N)]
            for i in range(N):
                C[(i+ind-j)%N] = B[i]
            B = C[:]
            cnt += ((ind-j)%N)*x
        else:
            B[j] = 1
            cnt += A[j]
print(cnt)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
magic=0
data=[0 for i in range(0,N)]
ans=10**20
test=0
for i in range(0,N):
    for j in range(0,N):
        if a[j-i]+x*i<a[j-data[j]]+x*data[j]:
            data[j]=i
    test=sum(a[j-data[j]] for j in range(0,N))+x*max(data)
    if test<ans:
        ans=test

print(ans)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
magic=0
data=[i for i in range(0,N)]
ans=10**20
test=0
for i in range(0,N):
    for j in range(0,N):
        if a[j-i]+x*i<a[j-data[j]]+x*data[j]:
            data[j]=i
    test=sum(a[j-data[j]] for j in range(0,N))+x*max(data)
    if test<ans:
        ans=test

print(test)

Submission status: Wrong Answer

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

data=[[0,0] for i in range(0,N)]
for i in range(0,N):
    test1=10**20
    test2=-1
    for j in range(0,i+1):
        if a[j]+(i-j)*x<test1:
            test1=a[j]+(i-j)*x
            test2=j
    for j in range(i+1,N):
        if a[j]+(N-(j-i))*x<test1:
            test1=a[j]+(N-(j-i))*x
            test2=j
    data[i][0]=test2
    data[i][1]=(test1-a[test2])//x

ans=0
for i in range(0,N):
    ans+=a[data[i][0]]

m=max(data[i][1] for i in range(0,N))

print(ans+m*x)

Submission status: Wrong Answer

Solution code:
#b faster
#m_i(k) = min(m_i(k-1), a_(i-k))
# http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf
n,x =  [int(i) for i in input().split()]
a   =  [int(i) for i in input().split()]
m   =  a[::]
a.extend(a)

min_cost = 10**10

for k in range(n):
    #cost = x * k
    for i in range(n,2*n):
        mini = min(m[i-n], a[i-k])
        m[i-n] = mini
        #cost += mini
    min_cost = min(min_cost, x*k + sum(m))
print(min_cost)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, x = map(int, input().split())
A = np.array(input().split()[::-1], dtype=np.int64)
B = A.copy()
ans = float("inf")
for k in range(n):
  print(B)
  t = x*k + B.sum()
  ans = min(ans, t)
  np.minimum(B, np.roll(A, -k-1), out=B)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, x = map(int, input().split())
A = np.array(input().split()[::-1]*2, dtype=np.int64)
B = A[:n]
ans = float("inf")
for k in range(n):
  t = x*k + B.sum()
  ans = min(ans, t)
  np.minimum(B, A[k+1:k+n+1], out=B)
print(ans)

Submission status: Wrong Answer

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

B = [[0] * 2 for i in range(n)]
for i in range(n):
    B[i][0] = A[i]
y = 0
for i in range(n):
    for j in range(n):
        t = (j-i)%n
        if B[j][0] + x*B[j][1] > A[t] + x*i:
            B[j][0] = A[t]
            B[j][1] = i
        
# print(B)
print(sum([i[0] for i in B]) + x * max([i[1] for i in B]))

Submission status: Wrong Answer

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

B = [[0] * 2 for i in range(n)]
for i in range(n):
    B[i][0] = A[i]
y = 0
for i in range(n):
    for j in range(n):
        t = (j-i)%n
        if B[j][0] + x*B[t][1] > A[t] + x*i:
            B[j][0] = A[t]
            B[j][1] = i
        
# print(B)
print(sum([i[0] for i in B]) + x * max([i[1] for i in B]))

Submission status: Wrong Answer

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

B = [[0] * 2 for i in range(n)]
for i in range(n):
    B[i][0] = A[i]
y = 0
for i in range(n):
    for j in range(n):
        t = (j-i)%n
        if B[t][0] + x*B[t][1] > A[j] + x*i:
            B[t][0] = A[j]
            B[t][1] = i
        
# print(B)
print(sum([i[0] for i in B]) + x * max([i[1] for i in B]))

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
n,x = map(int,input().split())
a = list(map(int,input().split()))
a *= 2
als = deepcopy(a[:n])
ans = [sum(als)]
for k in range(1,n):
  for i in range(n):
    als[i] = min(als[i],a[n-1+i-k])
  ans.append(sum(als)+x*k)
print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
from copy import deepcopy
n,x = map(int,input().split())
a = list(map(int,input().split()))
a *= 2
als = deepcopy(a[:n])
ans = [sum(als)]
for k in range(1,n):
  for i in range(n):
    als[i] = min(als[i],a[n-1+i-k])
  ans.append(sum(als)+x*k)
print(min(ans))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=list(accumulate(a))
for i in range(n):
  ans[i]+=(n-1-i)*x
print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, x = map(int, input().split())
a = list(map(int, input().split()))
res = float("inf")
import heapq

class prim:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def MSTcost(self):
    h = []
    visited = [0] * (self.n + 1)
    ks = list(self.e.keys())
    b = pow(10, 10)
    for edge in self.e[ks[0]]:
      heapq.heappush(h, edge[1] * b + edge[0])
    res = 0
    visited[ks[0]] = 1
    while len(h):
      p = heapq.heappop(h)
      p0 = p // b
      p1 = p % b
      if visited[p1]: continue
      visited[p1] = 1
      for q in self.e[p1]:
        if visited[q[0]]:
          continue
        heapq.heappush(h, q[1] * b + q[0])
      res += p0
    return res
e = dd(list)
for k in range(N + 1):
  for i in range(N):
    e[N].append(((i + k) % N, a[i]))
  pri = prim(N, e)
  res = min(res, pri.MSTcost() + k * x)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, x = map(int, input().split())
a = list(map(int, input().split()))
res = float("inf")
import heapq

class prim:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def MSTcost(self):
    h = []
    visited = [0] * (self.n + 1)
    ks = list(self.e.keys())
    b = pow(10, 10)
    for edge in self.e[ks[0]]:
      heapq.heappush(h, edge[1] * b + edge[0])
    res = 0
    visited[ks[0]] = 1
    while len(h):
      p = heapq.heappop(h)
      p0 = p // b
      p1 = p % b
      if visited[p1]: continue
      visited[p1] = 1
      for q in self.e[p1]:
        if visited[q[0]]:
          continue
        heapq.heappush(h, q[1] * b + q[0])
      res += p0
    return res
e = dd(list)
for k in range(N + 1):
  for i in range(N):
    e[N].append(((i + k) % N, a[i]))
  pri = prim(N, e)
  res = min(res, pri.MSTcost() + k * x)
print(res)

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
a = list(map(int, input().split()))
cost = a[:]
use = [i for i in range(n)]
ans = sum(a)
for k in range(1,n):
  for i in range(n):
    j = (i-k)%n
    if cost[i] > a[j] + x*k:
      cost[i] = a[j] + x*k
      use[i] = j
  cur = k*x + sum(a[x] for x in use)
  if ans > cur:
    ans = cur
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
a = list(map(int, input().split()))
cost = a[:]
use = [i for i in range(n)]
for i in range(n-1):
  for j in range(i+1,n):
    if cost[j] > cost[i] + x*(j-i):
      cost[j] = cost[i] + x*(j-i)
      use[j] = use[i]
    if cost[i] > cost[j] + x*(n+i-j):
      cost[i] = cost[j] + x*(n+i-j)
      use[i] = use[j]
catch = 0
change = 0
for i in range(n):
  catch += a[use[i]]
  if change < (i - use[i])%n:
    change = (i - use[i])%n
print(catch + change*x)

Submission status: Wrong Answer

Solution code:
def main():
    N, X = map(int, input().split())
    *A, = map(int, input().split())

    ret = 10 ** 14
    for magic_count in range(N):
        for slime_idx in range(N):
            A[slime_idx] = min(A[slime_idx], A[slime_idx - magic_count])
        ret = min(ret, sum(A) + X * magic_count)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, X = map(int, input().split())
    *A, = map(int, input().split())

    ret = 10 ** 13
    for magic_count in range(N):
        for slime_idx in range(N):
            A[slime_idx] = min(A[slime_idx], A[slime_idx - magic_count])
        ret = min(ret, sum(A) + X * magic_count)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
# スライムの色は0-initialで考える
# スライムiを捕まえてスライムjに変化させるために必要な時間をc[i][j]とする
c=[[-1 for j in range(N)] for i in range(N)]
# スライムjを捕まえてスライムiに変化させるために必要な時間をdとする
d=[[-1 for j in range(N)] for i in range(N)]

for i in range(N):
    for j in range(N):
        d[(i+j)%N][i]=c[i][(i+j)%N]=a[i]+x*j
'''
for ci in c:
    print(ci)
print()
for di in d:
    print(di)
print()
'''
# スライムiを最も早く得るために必要なスライムj=s[i]と魔法を唱える回数k[i]=(j-i)%Nを計算する
s=[d[i].index(min(d[i])) for i in range(N)]
k=[(s[i]-i)%N for i in range(N)]
'''
print(s)
print(k)
'''
# 魔法を唱える回数の最大値(=魔法を唱える回数の合計)*xに，各スライムを捕まえるのに必要な時間Σa[s[i]]を合計する
ans=max(k)*x+sum([a[s[i]] for i in range(N)])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,x=map(int,input().split())
    A=[]
    A.append(list(map(int,input().split())))

    for _ in range(n-1):
        now=A[-1]
        next=[now[(i+1)%n]+x for i in range(n)]
        A.append(next)

    k=0
    ans=0
    for j in range(n):
        i=min((A[i][j],i) for i in range(n))[1]
        ans+=A[0][(i+j)%n]
        k=max(k,i)

    ans+=k*x
    print(min(ans,sum(A[0])))
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,x=map(int,input().split())
    A=[]
    A.append(list(map(int,input().split())))

    for _ in range(n-1):
        now=A[-1]
        next=[now[(i+1)%n]+x for i in range(n)]
        A.append(next)

    k=0
    ans=0
    for j in range(n):
        i=min((A[i][j],i) for i in range(n))[1]
        ans+=A[0][(i+j)%n]
        k=max(k,i)

    ans+=k*x
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
A = list(map(int, input().split()))*2
m = 0
ans = 0
for i in range(n):
  c, t = A[i], A[i]
  for j in range(1, n):
    if c > A[i+n-j]+j*x:
      c = A[i+n-j]+j*x
      t = A[i+n-j]
      m = max(m, j)
  ans += t
print(ans+m*x)

Submission status: Wrong Answer

Solution code:
n,X = map(int,input().split())
L = list(map(int,input().split()))
min1 = min(L)
cnt = 0
ans = 0
for i in range(n):
    if L[i] > X:
        cnt += 1
        ans += X+min1
    else:
        ans += L[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
*A, = map(int, input().split())
MAX = 10**10
B = [MAX]*N
ans = MAX
for k in range(N):
    for i in range(N):
        B[i] = min(B[i], A[(i-k) % N])
    ans = min(ans, k*x + sum(B))
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
*A, = map(int, input().split())
B = A[:]
ans = 10**10
for k in range(N):
    ans = min(ans, k*x + sum(B))
    for i in range(N):
        B[i] = min(B[i], A[(i-(k+1)) % N])
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
*A, = map(int, input().split())
B = A[:]
ans = 10**10
for k in range(N):
    ans = min(ans, k*x + sum(B))
    for i in range(N):
        B[i] = min(B[i], B[(i-(k+1)) % N])
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ret = float('inf')
dp = [(float('inf'), 0) for _ in range(N)]
for i in range(N) :
    for j in range(N) :
        if a[j] + x * i < dp[(j+i)%N][0] :
            dp[(j+i)%N] = (a[j] + x * i, a[j])
    ret = min(ret, sum(dp[j][1] for j in range(N)) + x * i)

print(ret)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ret = float('inf')
dp = [(float('inf'), 0) for _ in range(N)]
for i in range(N) :
    for j in range(N) :
        if a[j] + x * i < dp[j-i][0] :
            dp[j-i] = (a[j] + x * i, a[j])
    ret = min(ret, sum(dp[j][1] for j in range(N)) + x * i)

print(ret)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ret = float('inf')
dp = [(float('inf'), 0) for _ in range(N)]
for i in range(N) :
    for j in range(N) :
        if a[j] + x * j < dp[j-i][0] :
            dp[j-i] = (a[j] + x * i, a[j])
    ret = min(ret, sum(dp[j][1] for j in range(N)) + x * i)

print(ret)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

l = []
for i in range(N) :
    ms, ma, mx = float('inf'), float('inf'), float('inf')
    for j in range(N) :
        if a[i-j] + x * j < ms :
            ms, ma, mx = a[i-j] + x * j, a[i-j], x * j
    l.append((ma, mx))
    
l.sort(key=lambda x: x[1], reverse=True)
print(sum(l[0]) + sum(l[i][0] for i in range(1, N)))

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

ret = float('inf')
for i in range(N) :
    ret = min(ret, sum([min(a[i]+x, a[j])for j in range(N)]))
print(ret)

Submission status: Wrong Answer

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

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

#a_ch = []
a_chmx = [0]*n
a_num = [0]*n
for i in range(n):
    mn_a = a[i]
    ind = i
    for j in range(n):
        #print(mn_a, x*((i-j+n)%n) + a[j])
        if mn_a > x*((i-j+n)%n) + a[j]:
            mn_a = a[j] + ((i-j+n)%n)*x
            ind = j#この項はここ
            if (i-j+n)%n>a_chmx[j]:
                a_chmx[j] = (i-j+n)%n
 
    #print(ind,i)
    a_num[ind] += 1
#print(a)
#print(a_chmx)
#print(a_num)
ans = 0
for i in range(n):
    ans += a[i]*a_num[i]
ans += sum(a_chmx)*x
print(ans)

Submission status: Wrong Answer

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

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

a_ch = []
mx_ji = 0
for i in range(n):
    mn_a = a[i]
    for j in range(n):
        if mn_a > x*((j-i+n)%n) + a[j]:
            mn_a = a[j]
            if (j-i+n)%n>mx_ji:
                mx_ji = (j-i+n)%n
    a_ch.append(mn_a)

print(sum(a_ch)+mx_ji*x)

Submission status: Wrong Answer

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

ans = 0
mx = 0
inf = float('INF')
for i in range(n):
    mn = a[i]
    con = a[i]
    for j in range(i-n,i+1):
        idx = j%n
        if mn > a[idx] + (i-j) * x:
            mn = a[idx] + (i-j) * x
            con = a[idx]
            if mx < (i-j):
                mx = (i-j)
    ans += con
print(ans + mx * x)

Submission status: Wrong Answer

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

ans = 0
mx = 0
inf = float('INF')
for i in range(n):
    mn = a[i]
    con = a[i]
    for j in range(i-n,i+1):
        idx = (i-j)%n
        if mn > a[idx] + (i-j) * x:
            mn = a[idx] + (i-j) * x
            con = a[idx]
            if mx < (i-j):
                mx = (i-j)
    ans += con
print(ans + mx * x)

Submission status: Wrong Answer

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

ans = 0
mx = 0
inf = float('INF')
for i in range(n):
    mn = a[i]
    con = a[i]
    for j in range(i-n,i+1):
        tmp = (i-j)%n
        if mn > a[j] + tmp * x:
            mn = a[j] + tmp * x
            con = a[j]
            if mx < tmp:
                mx = tmp
    ans += con
print(ans + mx * x)

Submission status: Wrong Answer

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

ans = 0
mx = 0
inf = float('INF')
for i in range(n):
    mn = a[i]
    con = a[i]
    for j in range(n):
        tmp = (i-j)%n if j > i else i-j
        if mn > a[j] + tmp * x:
            mn = a[j] + tmp * x
            con = a[j]
            if mx < tmp:
                mx = tmp
    ans += con
print(ans + mx * x)

Submission status: Wrong Answer

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

ans = 0
mx = 0
inf = float('INF')
for i in range(n):
    mn = a[i]
    con = a[i]
    for j in range(n):
        tmp = n+i-j if j > i else i-j
        if mn > a[j] + tmp * x:
            mn = a[j] + tmp * x
            con = a[j]
            if mx < tmp:
                mx = tmp
    ans += con
print(ans + mx * x)

Submission status: Wrong Answer

Solution code:
N,x =map(int,input().split())
lsta = list(map(int,input().split()))
cost = [0 for i in range(N)]
ans = 0
mina = 99999999

for i in range(N):
  if mina > lsta[i]:
    mina = lsta[i]
  if lsta[i] <= x:
    cost[i] = lsta[i]
    mina =0
if mina != 0:
  for i in range(N):
    if lsta[i] == mina:
      cost[i] = mina
  #buy_pos.append(mina)

while True:
  if not (0 in cost):
    break
  for i in range(N):
    if cost[i-1] != 0 and cost[i] ==0:
      if lsta[i] <= cost[i-1] + x:
        cost[i] = lsta[i]
      else:
        cost[i] = cost[i-1]+x
print(sum(cost))

Submission status: Wrong Answer

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

ans = 0
mx = 0
inf = float('INF')
for i in range(n):
    mn = inf
    idx = i
    for j in range(i,n+i):
        j = j % n
        tmp = n+i-j if j > i else i-j
        if mn > a[j] + tmp * x:
            mn = a[j]
            if mx < tmp:
                mx = tmp
    ans += mn
print(ans + mx * x)

Submission status: Wrong Answer

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

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

ans = 0
inf = float('INF')
for i in range(n):
    mn = inf
    for j in range(n):
        ab = abs(i-j)
        tmp = n - ab if n < ab * 2 else ab
        if mn > a[j] + tmp * x:
            mn = a[j] + tmp * x
    ans += mn
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
inf = float('INF')
for i in range(n):
    mn = inf
    for j in range(n):
        tmp = abs(n+i-j) if abs(n+i-j) < abs(i-j) else abs(i-j) 
        if mn > a[j] + tmp * x:
            mn = a[j] + tmp * x
    ans += mn
print(ans)

Submission status: Wrong Answer

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

amin = 10**10
for i in range(N):
    if a[i] <= amin:
        start_list = [i]
        amin = a[i]
    elif a[i] == amin:
        start_list.append(i)

ans_min = float('inf')
for start in start_list:
    cnt = 0
    tmp = 0
    use = 0
    ans = 0
    for _i in range(N):
        i = (_i + start) % N
        if a[i] < amin + x:
            tmp = a[i]
            use = cnt
            ans += tmp
        else:
            if use > 0:
                use -= 1
                ans += tmp
            else:
                cnt += 1
                ans += amin + x
    ans_min = min(ans, ans_min)

print(ans_min)

Submission status: Wrong Answer

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

amin = 10**10
start = 0
for i in range(N):
    if a[i] < amin:
        start = i
        amin = a[i]

cnt = 0
tmp = 0
use = 0
ans = 0
for _i in range(N):
    i = (_i + start) % N
    if a[i] < amin + x:
        tmp = a[i]
        use = cnt
        ans += tmp
    else:
        if use > 0:
            use -= 1
            ans += tmp
        else:
            cnt += 1
            ans += amin + x

print(ans)

Submission status: Wrong Answer

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

ans = 0
am = min(a)
for ai in a:
    ans += min(am+x, ai)
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
start=0
ans=0;cnt=0
for i in range(n):
  if a[i]<a[start]:start=i
for i in range(n):
  if a[i]>x:
    ans+=x
    cnt+=1
  else:ans+=a[i]
print(ans+a[start]*cnt)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
start=0
ans=0;cnt=0
for i in range(n):
  if a[i]<a[start]:start=i
for i in range(n):
  if a[i]>x:
    ans+=x
    cnt+=1
  else:ans+=a[i]
print(ans+x*cnt)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a*=2
INF=10**15
cost=[INF]*n
start=0
for i in range(n):
    if a[i]<a[start]:start=i
cost[start]=a[start]
for i in range(start+1,start+n):
    cost[i%n]=min(cost[(i-1)%n]+x,cost[i%n])
ans=0
for i in cost:
    if i==INF:continue
    ans+=i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,x = II()
a = III()

ans = 0
move_max = 0
for i in range(N):
    val = float('inf')
    for j in range(N):
        now = a[(i-j)%N] + j*x
        if now<val:
            val = now
            move = j
    if move>move_max:
        move_max = move
    ans += val-move*x

ans += move_max*x
print(ans)

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

N, x = getlist()
a = getlist()
ans1 = 0
ans2 = 0

for i in range(N):
	lis = []
	for j in range(N):
		lis.append(a[i - j] + j * x)
	ind = lis.index(min(lis))
	ans1 += lis[ind] - x * ind
	ans2 = max(ans2, ind)
print(ans1 + ans2 * x)

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():

    n,x = mi()
    a = li()
    flag = [0 for i in range(n)]

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

    a = a+a
    flag= flag+flag

    p = 0
    while(flag[p] == 1):
        p+=1
    po = p
    p+=1
    ans= 0
    maxpo = 0
    while(p < n or flag[p] == 1):
        if flag[p] == 0:
            ans+=a[po] * (p-po)
            maxpo = max(p-po-1,maxpo)
            po = p
        p+=1
    ans+=a[po] * (p-po)
    ans+=max(p-po-1,maxpo)*x





    print(ans)
            


main()

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():

    n,x = mi()
    a = li()
    flag = [0 for i in range(n)]

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

    a = a+a
    flag= flag+flag

    p = 0
    while(flag[p] == 1):
        p+=1
    po = p
    p+=1
    ans= 0
    while(p < n or flag[p] == 1):
        if flag[p] == 0:
            ans+=a[po] * (p-po)
            ans+=(p-po-1)*x
            po = p
        p+=1
    ans+=a[po] * (p-po)
    ans+=(p-po-1)*x





    print(ans)
            


main()