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: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import copy

def solve(N: int, x: int, a: "List[int]"):
    cost = sum(a)
    for i in range(N):
        a = [a[j-1] if a[j] > a[j-1] else a[j] for j in range(N)]
        cost = min([cost, sum(a) + x * (i + 1)])
    print(cost)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, x, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dp = [[0 for _ in range(N)] for i in range(N)]
for i in range(N):
    dp[i][i] = a[i]
    for k in range(1, N):
        j = (i + k) % N
        dp[i][j] = min(dp[i][(j - 1) % N], a[j])

# 変色回数を0からN-1まで決め打ちして解を求める
ans = min(
    sum(dp[i][(i + k) % N] for i in range(N)) + k * x
    for k in range(N)
)

# 出力
print(ans)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a[:]
d=sum(a)
for magic in range(n):
    b=[min(b[i],a[i-magic])for i in range(n)]
    d=min(d,sum(b)+magic*x)
print(d)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a[:]
d=sum(a)
for j in range(1,n):
    b=[min(b[i],a[i-j])for i in range(n)]
    d=min(d,sum(b)+j*x)
print(d)

Submission status: Accepted

Solution code:
import sys
from copy import copy


fin = sys.stdin.readline
N, x = [int(elem) for elem in fin().split()]
a_list = [int(elem) for elem in fin().split()]

min_total_cost = float('inf')
min_so_far = a_list[:]
for num_magics in range(N):
    for i in range(N):
        min_so_far[i] = min(min_so_far[i], a_list[i - num_magics])
    total_cost = sum(min_so_far) + num_magics * x
    min_total_cost = min(min_total_cost, total_cost)
print(min_total_cost)

Submission status: Accepted

Solution code:
import sys
from copy import copy


fin = sys.stdin.readline
N, x = [int(elem) for elem in fin().split()]
a_list = [int(elem) for elem in fin().split()]

min_total_cost = float('inf')
min_so_far = a_list[:]
for num_magics in range(N):
    for i in range(N):
        min_so_far[i] = min(min_so_far[i], a_list[i - num_magics])
    total_cost = sum(min_so_far) + num_magics * x
    min_total_cost = min(min_total_cost, total_cost)
print(min_total_cost)

Submission status: Accepted

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

orig = A[:]
ans = float("inf")

for k in range(N):
    tmp = k * X  
    for i in range(3*N):
        j = (i-k+N*6) % N
        i = i % N
        A[i] = min(A[i], orig[j])

    tmp += sum(A)
    ans = min(ans, tmp)
    
print(ans)

Submission status: Accepted

Solution code:
n,x=map(int, input().split())
lst=list(map(int, input().split()))
ms=lst
lst=lst*2
ans=10**15
s=0
for i in range(n):
    s=i*x
    for j in range(n):
        ms[j]=min(ms[j],lst[n+j-i])
        s+=ms[j]
    ans=min(ans,s)
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
alist = list(map(int, input().split()))
blist = alist[:]

ans = None
for i in range(n):
  for j in range(n):
    blist[j] = min(blist[j], alist[j-i])
  if ans is None:
    ans = i * x + sum(blist)
  else:
    ans = min(ans, i * x + sum(blist))
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, x = map(int, input().split())
A = list(map(int, input().split()))
A += A
A = np.array(A, int)
INF = 10 ** 18
ans = INF
B = np.ones(N, int) * INF
for cnt in range(N):
    np.minimum(A[N-cnt:2*N-cnt], B, B)
    ans = min(ans, cnt * x + np.sum(B))

print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A += A
INF = 10 ** 18
ans = INF
B = [INF] * N
for cnt in range(N):
    for i in range(N):
        B[i] = min(B[i], A[N + i - cnt])
    ans = min(ans, cnt * x + sum(B))

print(ans)

Submission status: Accepted

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

mi = 10**100
for j in range(N):
    s = 0
    for i in range(N):
        s += M[i]
        
    mi = min(mi, s+x*j)
    M = [min(M[i], A[(i-j-1) % N]) for i in range(N)]

print(mi)

Submission status: Accepted

Solution code:
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.copy(a)
ans = float('inf') 
for i in range(N):
    c = np.roll(a,i)
    b = np.minimum(b,c)
    ans = min(ans, sum(b)+i*x)
print(ans)

Submission status: Accepted

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

ans = float("inf")
bik = A[:]

get_idx_back = lambda idx,b: idx-b if idx>=b else idx+N-b

for loop in range(0, N+1):
  if loop == 0:
      bik = A[:]
  else: 
      for i in range(N):
          bik[i] = min(bik[i], A[ get_idx_back(i, loop) ])

  tmp = (loop)*X + sum(bik)

  ans = min(tmp, ans)
print(ans)
exit(0)

Submission status: Accepted

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]:
                dp[i + 1] = dp[i]
            tmp += dp[i + 1]

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

    return res


print(main())

Submission status: Accepted

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[j] = min(DP[j], DP[j-1])
    DP=new
    ans = min(ans, sum(DP) + (i+1)*x)
print(ans)

Submission status: Accepted

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):
    DP = [min(DP[j],DP[j-1]) for j in range(n)]
    ans = min(ans, sum(DP) + (i+1)*x)
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,x=map(int,input().split())
A=list(map(int,input().split()))
T=A[:]
ans=sum(T)
for j in range(1,n):
    T=[min(T[i],A[i-j]) for i in range(n)]
    ans=min(ans,sum(T)+x*j)
print(ans)

Submission status: Accepted

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

#p[i色のスライム][j回まで色を変えられる]=色変えのコストを含まない最小コスト
p = [[0]*n for i in range(n)]

#print(p)
for i in range(n):
  p[i][0]=a[i]
  for j in range(1,n):
    if i-j>=0:
      p[i][j]=min(a[i-j],p[i][j-1])
    elif i-j == -1:
      p[i][j]=min(a[n-1],p[i][j-1])
    else:  
      p[i][j]=min(a[n-(j-i)],p[i][j-1])
p = list(zip(*p))
ans = sum(p[0])
for i in range(1,n):
  ans = min(ans,sum(p[i])+x*i)
print(ans)

Submission status: Accepted

Solution code:
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
min_costs = [float("inf") for n in range(loop)]
for i in range(loop):
    for j in range(loop):
        min_costs[j] = min(min_costs[j], cost[(i - j) % loop])
    answer = min(answer, sum(min_costs) + (magic_cost * (i) ) )
print(answer)

Submission status: Accepted

Solution code:
n,x=map(int, input().split())
a=list(map(int, input().split()))
b=a[:]
ans=float('inf')
for i in range(n):
    for j in range(n):
        b[j]=min(b[j],a[j-i])
    ans=min(ans,sum(b)+x*i)
print(ans)

Submission status: Accepted

Solution code:
N, x = map(int,input().split())
A = list(map(int,input().split()))
T = [A[k] for k in range(N)]

ans = sum(A)
A = A+A

for k in range(1,N):
    for l in range(N):
        T[l] = min(T[l],A[N+l-k])
    ans = min(ans,sum(T)+k*x)

print(ans)

Submission status: Accepted

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 = 1e15
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: Accepted

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

ans = float("inf")
cost_list = [float("inf") for _ in range(N)]
for i in range(N):
    cost = 0
    for j in range(N):
        if i == 0:
            cost += a_list[j]
            cost_list[j] = a_list[j]
        else:
            tmp = cost_list[j]
            if tmp > a_list[- i + j]:
                cost_list[j] = a_list[- i + j]
                cost += a_list[- i + j]
            else:
                cost += tmp

    cost += x * i
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

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

ans = float("inf")
cost_list = [float("inf") for _ in range(N)]
for i in range(N):
    cost = 0
    for j in range(N):
        if i == 0:
            cost += ex_list[N + j]
            cost_list[j] = ex_list[N + j]
        else:
            tmp = cost_list[j]
            if tmp > ex_list[N - i + j]:
                cost_list[j] = ex_list[N - i + j]
                cost += ex_list[N - i + j]
            else:
                cost += tmp

    cost += x * i
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

Solution code:
N, x = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

ans = sum(A)
for k in range(1, N + 1):
    A = [min(i, j) for i, j in zip(A, A[1:] + [A[0]])]
    ans = min(ans, x * k + sum(A))
print(ans)

Submission status: Accepted

Solution code:
# AGC 004 B
N, x = map(int,input().split())
A = list(map(int,input().split()))

M = [[float("inf")]*N for k in range(N)]
for k in range(N):
    M[0][k] = A[k]

for k in range(N):
    for l in range(N):
        M[k][l] = min(M[k-1][l],A[k-l])

ans = sum(A)
for k in range(1,N):
    ans = min(ans,sum(M[k])+x*k)

print(ans)

Submission status: Accepted

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):
    for i in range(N):
        if B[i]>A[i-t]:
            B[i]=A[i-t]
    ans=min(ans,sum(B)+t*X)
print(ans)

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=[int(i) for i in input().split()]
for i in range(N):
  a.append(a[i])
dp=[[float("inf")]*N for i in range(N)]
ans=float("inf")
for k in range(N):
  for i in range(N):
    if k==0:
      dp[k][i]=a[N+i]
    else:
      dp[k][i]=min(dp[k-1][i],a[N+i-k])
  ans=min(ans,k*x+sum(dp[k]))
    
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
 
b = a[::]
ans = sum(a)
 
for k in range(1, n):
    b = [min(b[i], a[i - k]) for i in range(n)]
    ans = min(ans, sum(b) + k * x)
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
N, x = map(int, input().split())
A = [int(a) for a in input().split()]

minA = deepcopy(A)
Ans = sum(minA) #全て直接捕まえる場合
for i in range(1, N): #i回魔法を唱える
    for j in range(N):
        minA[j] = min(minA[j], A[j-i])
    Ans = min(Ans, x * i + sum(minA))
print(Ans)

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
import numpy as np
N, x = inpl()
a = np.array(inpl())
b = np.copy(a)
ans = float('inf') 
for i in range(N):
    c = np.roll(a,i)
    b = np.minimum(b,c)
    ans = min(ans, sum(b)+i*x)
print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
MIN = sum(a)
ans = MIN+0
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]:
      ans -= (tori[j] - a[ido])
      tori[j] = a[ido]
  MIN = min(ans + i*x,MIN)
print(MIN)

Submission status: Accepted

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

mins = [ai for ai in a]
a = a+a

ans = 10**18
for k in range(n):
    for i in range(n,2*n):
        mins[i-n] = min(mins[i-n], a[i-k])
        
    ans = min(ans, sum(mins) + x*k)
    
print(ans)

Submission status: Accepted

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], A[(j-i)%N])
        cost += costs[j]
    ans = min(ans, cost)

print(ans)

Submission status: Accepted

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

ans = float('inf')
costs = list(As)
for i in range(N):
    ans = min(ans, sum(costs) + x * i)
    costs = list(map(min, zip(costs, As[-i-1:] + As[:-i-1])))

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,x = map(int, input().split())
a = [int(i) for i in input().split()]
b = [a[i] for i in range(n)]

ret = sum(a)
for k in range(n):
    for i in range(n):
        b[i] = min(b[i], a[(i+n-k)%n])
    ret = min(ret, k*x+sum(b))
print(ret)

Submission status: Accepted

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(cost) + x * magic)

print(ans)

Submission status: Accepted

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

b = [] + a
ans = sum(a)
temp = [0 for _ in range(n)]
for i in range(1, n):
    r = a[n - i:] + a[:n - i]
    for j in range(n):
        temp[j] = min(b[j], r[j])
    ans = min(ans, sum(temp) + i * x)
    b = [] + temp

print(ans)

Submission status: Accepted

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

n,x = ai()
a = ai()

ma = [[] for _ in range(n)]
for i in range(n):
    ma[i].append(a[i])
    for j in range(1,n):
        if ma[i][-1] > a[i-j]:
            ma[i].append(a[i-j])
        else:
            ma[i].append(ma[i][-1])


def m(k):
    return sum(ma[i][k] for i in range(n))


print(min(m(k) + x*k for k in range(n)))

Submission status: Accepted

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+x*(i-1))
print(ans)

Submission status: Accepted

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

ans = sum(a)
mini = []
for i in range(n):
    mini.append(a[i])


for k in range(1,n+1): #魔法をかける回数
    total = 0
    for i in range(n):
        if mini[i] > a[(i-k+n)%n]:
            mini[i] = a[(i-k+n)%n]
        total += mini[i]
    total += k*x
    if total < ans:
        ans = total

print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = sum(a)
tempcost = ans
xt = 0
bc = a
for i in range(1, n):
    xt += x
    a = [a[-1]] + a[0:-1]
    bc = [v if v < bc[i] else bc[i] for (i, v) in enumerate(a)]
    tempcost = xt + sum(bc)
    ans = min(ans, tempcost)
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


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

min_cost_s = 0
tmp = INF
for i in range(N):
    if A[i] < tmp:
        min_cost_s = i
        tmp = A[i]

A = A[min_cost_s:] + A[:min_cost_s]
B = [A[i] for i in range(N)]

ans = INF
for shift in range(N):
    for i in range(N):
        if i - shift >= 0:
            B[i] = min(B[i], A[i - shift])
    # print(B)

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

print(ans)

Submission status: Accepted

Solution code:
N, x, *A = map(int, open(0).read().split())

B = A[:]
ans = sum(A)

for k in range(1, N):
    B = [min(B[i], A[i - k]) for i in range(N)]
    tmp = sum(B) + k * x
    if tmp < ans:
        ans = tmp
    else:
        break
print(ans)

Submission status: Accepted

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

B = A[:]
ans = sum(A)

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

Submission status: Accepted

Solution code:
N, x, *A = map(int, open(0).read().split())

B = A[:]
ans = sum(A)

for k in range(1, N):
    B = [min(v, A[i - k]) for i, v in enumerate(B)]
    ans = min(ans, sum(B) + k * x)
print(ans)

Submission status: Accepted

Solution code:
N, x, *A = map(int, open(0).read().split())

B = A[:]
ans = sum(A)

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

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

mins = [ai for ai in a]
a2 = a+a

ans = sum(mins)
for k in range(n):
    for i in range(n):
        mins[i] = min(mins[i],a2[i+k])
    
    temp = sum(mins)    
    ans = min(ans, temp + k*x)
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, x = inpl()
A = inpl()
ans = sum(A)

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

print(ans)

Submission status: Accepted

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

    min_t = 10 ** 15
    b = [10 ** 10 for i in range(n)]
    for i in range(n):
        t = i * x
        for j in range(n):
            b[j] = min(b[j], a[(j-i) % n])
            t += b[j]

        min_t = min(min_t, t)

    print(min_t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        B[j] = min(B[j], A[j-i])
    ans = min(ans, sum(B) + i * x)

print(ans)

Submission status: Accepted

Solution code:
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    B = [min(B[j], A[j-i]) for j in range(n)]
    ans = min(ans, sum(B) + i * x)

print(ans)

Submission status: Accepted

Solution code:
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        if A[j-i] < B[j]:
            B[j] = A[j-i]
    ans = min(ans, sum(B) + i * x)

print(ans)

Submission status: Accepted

Solution code:
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = [a for a in A]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        if A[j-i] < B[j]:
            B[j] = A[j-i]
    ans = min(ans, sum(B) + i * x)

print(ans)

Submission status: Accepted

Solution code:
N, X = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

def solve(N, X, A):
    M = A[:]
    result = sum(M)
    for i in range(1, N):
        M = [min(M[j], A[(j-i)%N]) for j in range(N)]
        r = sum(M) + X * i
        result = min(result, r)
    return result

print(solve(N, X, A))

Submission status: Accepted

Solution code:
N, X = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

def solve0(N, X, A):
    A2 = A + A
    T = [
        [min(A2[N+j+1-i-1:N+j+1]) for j in range(N)]
        for i in range(N)
    ]
    mins = [
        sum(T[i]) + i * X
        for i in range(N)
    ]
    result = min(mins)
    return result

def solve(N, X, A):
    M = A[:]
    result = sum(M)
    for i in range(1, N):
        M = [min(M[j], A[(j-i)%N]) for j in range(N)]
        r = sum(M) + X * i
        result = min(result, r)
    return result

print(solve(N, X, A))

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from random import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, x = reads()
A = reads()

INF = 1 << 60
smin = [[INF] * N for _ in range(N)]
for i in range(N):
  smin[i][0] = A[i]
  for j in range(1, N):
    smin[i][j] = min(smin[i][j-1], A[(i-j)%N])

ans = INF
for j in range(N):
  h = sum(smin[i][j] for i in range(N)) + x * j
  ans = min(ans, h)
print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = float("inf")
Mi = [float("inf")] * N
for i in range(N):
    for j in range(N):
        Mi[j] = min(Mi[j], A[j-i])
    ans = min(ans, x*i + sum(Mi))
print(ans)

Submission status: Accepted

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

mins = a[:]
result = float("inf")

for k in range(n):
    for i in range(len(mins)):
        mins[i] = min(a[i - k], mins[i])
    result = min(x * k + sum(mins), result)

print(result)

Submission status: Accepted

Solution code:
n,x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
ans,b,c = sum(a),[i for i in a],[i for i in range(n)]
for i in range(n):
	for j in range(n): c[j] = min(a[j-i],b[j])
	ans,b,c = min(ans,sum(c)+x*i),c,b
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int,input().split())
slimes = list(map(int,input().split()))
p = slimes[:]
ans = 5000000000000000

for i in range(n):
    for j in range(n):
        if p[j] > slimes[j-i]:
            p[j] = slimes[j-i]
    ans = min(ans, sum(p) + i * x)
print(ans)

Submission status: Accepted

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

#dp[i]:k回魔法を唱えた時にA[i]を手に入れる最小の時間。
#dp=Aで初期化。その後、１〜Nまでの各ステップでdp[i]はmin(dp[i],A[i-k])で順に更新されていく。
#各回におけるsum(dp)+k*xを算出して最小値が答え。

#ans初期値は魔法を唱えず、全てを入手した数字（sum(A))
ans=sum(A)
for k in range(1,N):
  for i in range(N):
    if dp[i]>A[i-k]:
      dp[i]=A[i-k]
  ans=min(ans,sum(dp)+x*k)

print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = float("INF")
b = [float("INF")]*N
for k in range(N):
    temp_ans = k*x
    for i in range(N):
        t = a[i-k]
        if t < b[i]:
            b[i] = t
        temp_ans += b[i]
    ans = min(ans,temp_ans)
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    ans = float("INF")
    b = [float("INF")]*N
    for k in range(N):
        temp_ans = k*x
        for i in range(N):
            t = a[i-k]
            if t < b[i]:
                b[i] = t
            temp_ans += b[i]
        ans = min(ans,temp_ans)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    ans = float("INF")
    b = [float("INF")]*N
    for k in range(N):
        temp_ans = k*x
        for i in range(N):
            b[i] = min(b[i],a[i-k])
            temp_ans += b[i]
        ans = min(ans,temp_ans)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = float("INF")
b = [[float("INF")]*N for _ in range(N)]
b[0] = a
for k in range(N):
    for i in range(N):
        b[k][i] = min(b[k-1][i],a[i-k])
    ans = min(ans, sum(b[k])+k*x)

print(ans)

Submission status: Accepted

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, x] = [int(input_raw[0]), long(input_raw[1])]
    A = []
    input_raw = read_func().strip().split()
    for i in range(N):
        A.append(long(input_raw[i]))

    min_time = long(sys.maxint * sys.maxint)
    min_A = [0L for i in range(N)]
    for k in range(N):
        sum_min_A = 0L
        for i in range(N):
            if k == 0:
                min_A[i] = A[i]
            else:
                i + k
                min_A[i] = min(min_A[i], A[(i + k)%N])
            sum_min_A += min_A[i]
        time = sum_min_A + x * long(k)
        if time < min_time:
            min_time = time
    print min_time

##    max_shift_num = 0L
##    sum_Aj = 0L
##    for i in range(N):
##        min_time = A[i]
##        min_Aj = A[i]
##        min_time_shift_num = 0L
##        for j in range(N):
##            if i == j:
##                continue;
##            if i - j < 0:
##                shift_num = N + (i - j)
##            else:
##                shift_num = i - j
##            time = shift_num * x + A[j]
##            if time < min_time:
##                min_time = time
##                min_Aj = A[j]
##                min_time_shift_num = shift_num
##        sum_Aj += min_Aj
##        if  min_time_shift_num > max_shift_num:
##            max_shift_num = min_time_shift_num
##    print sum_Aj + max_shift_num * x


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
b = [None] * n
for i, c in enumerate(a):
    b[i] = [None] * n
    b[i][0] = a[i]
    for j in range(1, n): b[i][j] = min(b[i][j - 1], a[(i - j) % n])
d = None
for i in range(n):
    c = i * x
    for j in range(n): c += b[j][i]
    if d is None or c < d:
        d = c
print(d)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split())) * 2
A = A[::-1]

effective_costs = [float('inf')] * N
ans = float('inf')

# 魔法を使う回数
for k in range(N):
    effective_costs = [min(effective_costs[i], A[i+k]) for i in range(N)]
    ans = min(ans, sum(effective_costs) + k * x)

print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
lowest_costs = A[:]
ans = float('inf')

for k in range(N):
    lowest_costs = [min(lowest_costs[i], A[i-k]) for i in range(N)]
    ans = min(sum(lowest_costs) + x * k, ans)

print(ans)

Submission status: Accepted

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

# 魔法0回のときの合計時間
ans = sum(a)
time = a[:]

# 魔法をj回唱える
for j in range(1, n):
    # 色iのスライムを得る最短時間はmin(a[i-j:i+1]) + j * x
    for i in range(n):
        time[i] = min(time[i], a[i - j])
    ans = min(ans, j * x + sum(time))

print(ans)

Submission status: Accepted

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, x = map(int, input().split())
a = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
src = list(map(int,input().split()))
dp = src[:]
ans = float('inf')
for n in range(N):
    for m in range(N):
       if dp[m] > src[m-n]:
           dp[m] = src[m-n]
    ans = min(ans, sum(dp)+n*X)
print(ans)