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

b = a.copy()
c = [0]*n

for i in range(n):
    d = []
    for j in range(n):
        s = i-j if j <= i else n+i-j
        if a[j]+x*s <= b[i]:
            if a[j]+x*s == b[i]:
                d.append(s)
            else:
                b[i] = a[j]+x*s
                d = [s]
    c[min(d)] += 1
d = 0
e = 0
for i in range(1, n):
    d -= i*x*c[i]
    if c[i] != 0:
        e = i
print(sum(b) + d + e*x)

Submission status: Wrong Answer

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

b = a.copy()
c = [0]*n

for i in range(n):
    d = []
    for j in range(n):
        s = i-j if j <= i else n+i-j
        if a[j]+x*s <= b[i]:
            if a[j]+x*s == b[i]:
                d.append(s)
            else:
                b[i] = a[j]+x*s
                d = [s]
    c[min(d)] += 1
d = 0
l = 0
for i in range(2, n):
    if c[i] > 0:
        d = d - i*x*c[i] + (i-l-1)*x
        l = i
print(sum(b)+d)

Submission status: Wrong Answer

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

b = a.copy()
c = [0]*n

for i in range(n):
    for j in range(n):
        s = i-j if j <= i else n+i-j
        b[i] = min(b[i], a[j]+x*s)
    t = n-1
    for j in range(n):
        s = i-j if j <= i else n+i-j
        if a[j]+x*s == b[i]:
            t = min(t, s)
    c[t] += 1
d = 0
l = 0
for i in range(2, n):
    if c[i] > 0:
        d = d - i*x*c[i] + (i-l-1)*x
        l = i
print(sum(b)+d)

Submission status: Wrong Answer

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

b = a.copy()
c = [0]*n

for i in range(n):
    t = n-1
    for j in range(n):
        s = i-j if j <= i else n+i-j
        if a[j]+x*s <= b[i]:
            b[i] = a[j]+x*s
            t = s
    c[t] += 1
d = 0
l = 0
for i in range(2, n):
    if c[i] > 0:
        d = d - i*x*c[i] + (i-l-1)*x
        l = i
print(sum(b)+d)

Submission status: Wrong Answer

Solution code:
class SegTree:
    def __init__(self, vals, seg_f, ide_ele):
        n = len(vals)
        self.seg_f = seg_f
        self.ide_ele = ide_ele
        self.leaf_n = 1 << (n-1).bit_length()
        self.tree = [ide_ele]*(2*self.leaf_n-1)
        for i in range(n):  # init leaf
            self.tree[i+self.leaf_n-1] = vals[i]
        for i in range(self.leaf_n-2, -1, -1):  # bottom-up
            self.tree[i] = self.seg_f(self.tree[2*i+1], self.tree[2*i+2])

    def update(self, i, x):
        i += (self.leaf_n-1)
        self.tree[i] = x
        while i > 0:
            i = (i-1)//2
            self.tree[i] = self.seg_f(self.tree[2*i+1], self.tree[2*i+2])

    # [l,r)
    def query(self, l, r):
        v_l = self.ide_ele
        v_r = self.ide_ele
        l += (self.leaf_n-1)
        r += (self.leaf_n-1)
        while l < r:
            if l&1 == 0:
                v_l = self.seg_f(v_l, self.tree[l])
            if r&1 == 0:
                v_r = self.seg_f(v_r, self.tree[r-1])
                r -= 1
            l >>= 1
            r >>= 1
        return self.seg_f(v_l ,v_r)


n,x = map(int, input().split())
al = list(map(int, input().split()))

st = SegTree(al, min, 10**18)
ans = 10**18
for i in range(0,n): # move cnt
    curr_i_ans = i*x
    for j in range(n): # ind
        l = j-i
        if l >= 0:
            print(l,j+1)
            amin = st.query(l,j+1)
        else:
            print(l+n,n+1)
            amin1 = st.query(0,j+1)
            amin2 = st.query(l+n,n)
            amin = min(amin1,amin2)
        curr_i_ans += amin
    ans = min(ans, curr_i_ans) 
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,x = MI()
A = LI()

B = [x+A[i]-A[i+1] for i in range(N-1)]+[A[-1]-A[0]]
B.sort()

print(sum(A)+B[0]*(N-1) if B[0] < 0 else sum(A))

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
INF = (1<<32)-1
cum = [[INF]*N for _ in range(N)]
for i in range(N):
  for j in range(i,N):
    cum[i][j] = min(cum[i][j-1],A[j])
ans = INF
for k in range(N):
  score = 0
  for j in range(N):
    if j-k>=0:
      score += cum[j-k][j]
    else:
      score += min(cum[0][j],cum[(j-k)%N][-1])
  ans = min(ans, k*x+score)
print(ans)

Submission status: Wrong Answer

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

cnt = [0] * N
move = [0] * N

for i in range(N):
    cost = 10 ** 18
    idx = i
    mv = 0
    for j in range(i + 1, i + N + 1):
        tmp = A[j] + x * (i + N - j)
        if cost >= tmp:
            cost = tmp
            idx = j % N
            mv = i + N - j
    cnt[idx] += 1
    move[idx] = max(move[idx], mv)

ans = 0
for a, c, m in zip(A, cnt, move):
    ans += a * c + m * x

print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A = A + A
Calc = []
X = 0
for i, a in enumerate(A):
    if i == 0:
        Calc.append((a, 0))
        continue
    b = Calc[i - 1][0] + x
    if b < a:
        Calc.append((b, Calc[i - 1][1] + 1))
        X = max(X, Calc[i - 1][1] + 1)
    else:
        Calc.append((a, 0))
ans = X * x
for i, j in Calc[N:]:
    ans += i - j * x
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
i=a.index(min(a))
a=a[i:]+a[:i]
k=a[0]
ans=0
for b in a:
  if b>=k+x:
    ans+=c+x
    k+=x
  else:
    ans+=b
    k=b
    c=b
print(ans)

Submission status: Wrong Answer

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

D = [a[i] for i in range(N)]
C = [0] * N
for i in range(N):
  for j in range(1, N):
    n = (i + j) % N
    t = a[i] + x * j
    if D[n] > t:
      D[n] = t
      C[n] = j

print(sum(D) - (sum(C) - max(C)) * x)

Submission status: Wrong Answer

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

D = [a[i] for i in range(N)]
C = [0] * N
for i in range(N):
  for j in range(1, N):
    n = (i - j) % N
    t = a[i] + x * j
    if D[n] > t:
      D[n] = t
      C[n] = j

print(sum(D) - (sum(C) - max(C)) * x)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = a
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = a
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],l[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
  ans = 0
  N, x = map(int, input().split())
  A = list(map(int, input().split()))
  for i in range(N):
    cnt = float('inf')
    for j in range(N):
      cnt = min(cnt,abs(i-j)*x+A[j])
    ans += cnt
  return ans
print(solve())

Submission status: Wrong Answer

Solution code:
from numba import njit
import numpy as np

@njit
def main(n,x,a):
    a_ori=a
    ans=np.sum(a)
    for i in range(1,n):
        tmp=0
        for j in range(n):
            a[j]=min(a[j],a_ori[j-i])
            tmp+=a[j]
        ans=min(ans,tmp+x*i)
    print(ans)

if __name__=='__main__':
    n,x=map(int,input().split())
    a=np.array(list(map(int,input().split())),np.int32)
    main(n,x,a)

Submission status: Wrong Answer

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

class SegmentTree:
    def __init__(self,data,op,default):
        N = len(data)
        self.N = N
        self.op = op
        self.default = default
        self.l = 2**((N-1).bit_length())
        self.data = [default]*self.l + data + [default]*(self.l-N)
        for i in range(self.l-1,0,-1):
            self.data[i] = op(self.data[2*i], self.data[2*i+1])

    def get_data(self, i = None):
        if i is None:
            return self.data[self.l:self.l+self.N]
        else:
            return self.data[self.l+i]

    def set(self,i,val):
        i += self.l
        self.data[i] = val
        i = i//2
        while i > 0:
            self.data[i] = self.op(self.data[2*i], self.data[2*i+1])
            i = i//2

    def get(self,i,j):
        i += self.l
        j += self.l
        s = self.default 
        while j-i > 0:
            if i & 1:
                s = self.op(s,self.data[i])
                i += 1
            if j & 1:
                s = self.op(s,self.data[j-1])
                j -= 1
            i, j = i//2, j//2
        return s

inf = 10**15
B = [(a+(N-1-i)*x,N-1-i) for i,a in enumerate(A)]
seg = SegmentTree(B,min,(inf,inf))

ans = 0
rs = []
for i in range(N):
    m, r= seg.get(0,N)
    rs.append(r)
    ans += m
    for j in range(N):
        v,tr = seg.get_data(j)
        t = (v-x, tr-1)
        seg.set(j, t)
    v,r = seg.get_data(N-1-i)
    t = (v+N*x, N-1)
    seg.set(N-1-i, t)

maxr=max(rs)
sumr=sum(rs)
print(ans-x*(sumr - maxr))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
INF=10*18
b=[INF]*n
b[0]=a[0]
for i in range(n):
  for j in range(1,n):
    b[j]=min(a[j],a[j-1]+x)
  if b[n-1]>b[0]:break
  b[0]=b[-1]
print(sum(b))

Submission status: Wrong Answer

Solution code:
def henkou(l,t):
  if l==t:
    return 0
  elif l>t:
    return x*(l-t)
  else:
    return x*(N+l-t)
s=0
mina=10**10
maxa=-10
k=0
m=10**10
L=list()
N,x=map(int,input().split())
a=list(map(int,input().split()))
for i in range(N):
  L.append(sum(a[:i+1]))
for i in range(N):
  for j in range(N):
    if mina>a[j]+henkou(i,j):
      m=henkou(i,j)
      s=j
      mina=a[j]+henkou(i,j)
  maxa=max(maxa,m)
  k+=a[s]
  mina=10**10
print(maxa+k)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = map(int, readline().split())
    a = list(map(int, readline().split()))
    ans = sum(a)
    cur_min = a[:]

    for cnt in range(1, n):
        score = cnt * x
        for i in range(n):
            cur_min[i] = min(cur_min[i], cur_min[(i - 1) % n])
        score += sum(cur_min)
        ans = min(ans, score)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,x = map(int,ipt().split())
    ca = [int(i) for i in ipt().split()]
    a = [(ca[i],i) for i in range(n)]
    for i in range(n):
        an = a[n-1]
        for j in range(n-1):
            pa = a[n-j-2]
            if a[n-1-j][0] > pa[0]+x:
                a[n-1-j] = (pa[0]+x,pa[1])
        if a[0][0] > an[0]+x:
            a[0] = (an[0]+x,an[1])
    ma = 0
    for i,ai in enumerate(a):
        if ma < (i-ai[1])%n:
            ma = (i-ai[1])%n
    ans = x*ma
    for i in range(n):
        mi = 10**10
        for j in range(ma+1):
            if mi > ca[i-j]:
                mi = ca[i-j]
        ans += mi
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

slimes = 0
magic = -1

for i in range(n):
    cost = 10**9
    m = 0
    s = 0
    for j in range(n):
        if j <= i:
            if cost > min(cost, a[j]+x*(i-j)):
                cost = min(cost, a[j] + x*(i-j))
                s = a[j]
                m = i-j
        else:
            if cost > min(cost, a[j]+x*(n-j+i)):
                cost = min(cost, a[j]+x*(n-j+i))
                s = a[j]
                m = n-j+i
    if magic < m:
        ind = i
        mx = s
        magic = max(magic, m)

for i in range(n):
    if i == ind:
        slimes += mx
        continue
    cost = 10**9
    s = 0
    for j in range(n):
        if j <= i:
            if cost > min(cost, a[j]+x*max((i-j)-magic, 0)):
                cost = min(cost, a[j] + x*max((i-j)-magic, 0))
                s = a[j]
                m = i-j
        else:
            if cost > min(cost, a[j]+x*max((n-j+i)-magic, 0)):
                cost = min(cost, a[j]+x*max((n-j+i)-magic, 0))
                s = a[j]
                m = n-j+i
    slimes += s

print(slimes + magic*x)

Submission status: Wrong Answer

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

slimes = 0
magic = 0

for i in range(n):
    cost = 10**9
    s = 10**9
    m = 0
    for j in range(n):
        if j <= i:
            if cost > min(cost, a[j]+x*(i-j)):
                cost = min(cost, a[j] + x*(i-j))
                s = a[j]
                m = i-j
        else:
            if cost > min(cost, a[j]+x*(n-j+i)):
                cost = min(cost, a[j]+x*(n-j+i))
                s = a[j]
                m = n-j+i
    slimes += s
    magic = max(magic, m)

print(slimes + magic*x)

Submission status: Wrong Answer

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

slimes = 0
magic = 0

for i in range(n):
    cost = 10**9
    s = 10**9
    m = 0
    for j in range(n):
        if j <= i:
            if cost > min(cost, a[j]+x*(i-j)):
                cost = min(cost, a[j] + x*(i-j))
                s = a[j]
                m = i-j
        else:
            if cost > min(cost, a[j]+x*(n-j+i)):
                cost = min(cost, a[j]+x*(i-j))
                s = a[j]
                m = n-j+i
    slimes += s
    magic = max(magic, m)

print(slimes + magic*x)

Submission status: Wrong Answer

Solution code:
# B - Colorful Slimes
N,x = map(int,input().split())
A = list(map(int,input().split()))
for j in range(N):
    A[j] = [A[j],A[j],0,j]
x_times = 0
ans = 0
for j in range(N):
    A.sort()
    sum_t,base,t,i = A.pop(0)
    for k in range(0,N-1-j):
        if base+(t+(A[k][3]-i)%N)*x<A[k][0]:
            A[k][0] = base+(t+(A[k][3]-i)%N)*x
            A[k][1] = base
            A[k][2] = t+(A[k][3]-i)%N
    x_times = max(x_times,t)
    ans += base
print(ans+x*x_times)

Submission status: Wrong Answer

Solution code:
# B - Colorful Slimes
N,x = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
    A[i] = [A[i],i,0]
A.sort()
for j in range(N):
    a0,i0,t0 = A[j]
    for k in range(j,N):
        a1,i1,t1 = A[k]
        if a0+(t0+(i1-i0)%N)*x<a1+t1*x:
            A[k][0] = a0
            A[k][2] = t0+(i1-i0)%N
x_times = max([A[j][2] for j in range(N)])
ans = sum([A[j][0] for j in range(N)])
ans += x*x_times
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, X = map(int, input().split())
A = np.array([int(x) for x in input().split()], dtype='int64')
B = np.array([a + (N-i-1) * X for i, a in enumerate(A)], dtype='int64')

ans = 0
maxx = 0
for i in range(N-1, -1, -1):
    j = np.argmin(B)
    ans += A[j]
    maxx = max(maxx, (i+N-j)%N)
    B[j] += N * X
print(ans + maxx*X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
  N, x = map(int, input().split())
  a = list(map(int, input().split()))
  c = [[a[i], i] for i in range(N)]
  ans = 0
  jj=[0]*N
  for i in range(N):
    tmp = 0
    for j in range(N):
      if c[(i+j) % N][0] > a[i] + tmp:
          c[(i+j) % N][0] = a[i] + tmp
          c[(i+j) % N][1] = i
          jj[(i+j)%N] = j
      tmp += x
  maxj = max(jj)
  for i in range(N):
    tmp = a[i]
    for j in range(maxj+1):
      tmp = min(a[i-j],tmp)
    ans+=tmp
  ans += maxj*x
  print(ans)
main()

Submission status: Wrong Answer

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

for i in range(N):
    tmp = 0
    for j in range(N):
        if c[(i+j) % N][0] > a[i] + tmp:
            c[(i+j) % N][0] = a[i] + tmp
            c[(i+j) % N][1] = i
            c[(i+j) % N][2] = j
        tmp += x
maxj = 0
for i in range(N):
    ans += a[c[i][1]]
    maxj = max(maxj, c[i][2])
ans += maxj*x
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    tmp = 0
    for j in range(N):
        tmp += x
        if c[(i+j) % N][0] > a[i] + tmp:
            c[(i+j) % N][0] = a[i] + tmp
            c[(i+j) % N][1] = i
            c[(i+j) % N][2] = j
maxj = 0
for i in range(N):
    ans += a[c[i][1]]
    maxj = max(maxj, c[i][2])
ans += maxj*x
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    tmp = 0
    for j in range(N):
        tmp += x
        if c[(i+j) % N][0] > a[i] + tmp:
            c[(i+j) % N][0] = a[i] + tmp
            c[(i+j) % N][1] = i

            ans = max(ans, j * x)
for i in range(N):
    ans += a[c[i][1]]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a_copy = a
for i in range(n):
  for j in range(n):
    idx = (i+j) % n
    time = a[i] + j*x
    a_copy[idx] = min(a_copy[idx], time)
print(sum(a_copy))

Submission status: Wrong Answer

Solution code:
N,x,*A = map(int, open(0).read().split())
dp = [0]*N
for i in range(N):
  m = float('inf')
  n = 0
  for j in range(N):
    p = (i-j)%N
    if j*x+A[p]<m:
      m = j*x+A[p]
      n = A[p]
    dp[j] += n
ans = float('inf')
for i in range(N):
  ans = min(ans,dp[i]+x*i)
print(ans)

Submission status: Wrong Answer

Solution code:
N,x,*A = map(int, open(0).read().split())
dp = [[0]*N for i in range(N)]
for i in range(N):
  m = 10**20
  n = 0
  for j in range(N):
    p = (i-j)%N
    if j*x+A[p]<m:
      m = j*x+A[p]
      n = A[p]
    dp[j][i] = n
    
ans = 10**20
for i in range(N):
  ans = min(ans,sum(dp[i])+x*i)
print(ans)

Submission status: Wrong Answer

Solution code:
N,x,*A = map(int, open(0).read().split())
dp = [[0]*N for i in range(N)]
for i in range(N):
  m = 10**10
  n = 0
  for j in range(N):
    p = (i-j)%N
    if j*x+A[p]<m:
      m = j*x+A[p]
      n = A[p]
    dp[j][i] = n
    
ans = 10**10
for i in range(N):
  ans = min(ans,sum(dp[i])+x*i)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A *= 2  # サイクルを処理しやすくするため2倍

get = [0] * N
move = [0] * N

for i in range(N):  # i番目のスライムの作り方
    pos = i  # 出現場所
    cost = A[i]
    for j in range(1, N):
        if cost > A[i + j] + x * j:
            pos = i + j

    get[pos % N] += 1
    move[pos % N] = max(move[pos % N], pos - i)


ans = sum(a * b for a, b in zip(A, get))
ans += max(move) * x
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N, x = map(int, input().split())
A = list(map(int, input().split()))
A *= 2  # サイクルを処理しやすくするため2倍

get = [0] * N
go = [0] * (2 * N + 1)


for i in range(N):  # i番目のスライムの作り方
    pos = i  # 出現場所
    cost = A[i]
    for j in range(1, N):
        if cost > A[i + j] + x * j:
            pos = i + j
    get[pos % N] += 1
    go[i] += 1
    go[pos] -= 1

go = list(accumulate(go))
move = list(accumulate(go[:N]))[-1]

ans = sum(a * b for a, b in zip(A, get))
ans += move * x
print(ans)

Submission status: Wrong Answer

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

memo = [[a, 0, a] for a in A]
for i in range(N):
  for j, a in enumerate(A):
    num = (i - j) % N
    memo[i] = min(memo[i], [a + x*num, num, a])

nums = [m[1] for m in memo]
max_num = max(nums)
ans = x * max_num
for i, (total_time, num, init_time) in enumerate(memo):
  if num:
    ans += init_time
  else:
    temp = init_time
    for diff in range(1, max_num+1):
      j = (i - diff) % N
      temp = min(temp, A[j])
    ans += temp

print(ans)

Submission status: Wrong Answer

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

memo = [[a, 0, a] for a in A]
for i in range(N):
  for j, a in enumerate(A):
    num = (i - j) % N
    memo[i] = min(memo[i], [a + x*num, num, a])

ans = 0
max_num = 0
for total_time, num, init_time in memo:
  ans += init_time
  max_num = max(max_num, num)

print(ans + max_num*x)

Submission status: Wrong Answer

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

b = [a[i%n] for i in range(n*2)]
stem = 0
wait = 0
for i in range(n):
    c = list(b[1+i:n+1+i])
    d = list(b[1+i:n+1+i])
    for j in range(n):
        c[-j-1] += x*j
    minim = 1e8
    minimidx = -1
    for j in range(n):
        if(c[j] < minim):
            minim = c[j]
            minimidx=j
    wait = max(wait, minim - d[minimidx])
    #print(minim,'m',c)
    stem += d[minimidx]

print(stem+wait)

Submission status: Wrong Answer

Solution code:
import math


N, X = map(int, input().split())
arr = list(map(int, input().split()))
"""
N, X = 2000, 1000
arr = []
for index in range(N):
    arr.append(randint(0,2000))
inventory = [] ## filled with indexes of arr to keep track
## im pretty sure that moving the prices is the same as moving the colour of the already had things
"""

## gaming time

def fastCosts(index, arr, N, X):
    ## dont I just need to add some constants to the list we already have
    costs = []
    ## what is each element of costs

    for counter in range(0, N):
        costs.append(arr[ (index-counter) % (N)] + counter*X)
    return costs

def elementWiseSum(list1, list2):
    if (len(list1) == 0):
        return list2
    if (len(list2) == 0):
        return list1
    for index in range(len(list1)):
        list1[index] += list2[index]
    return list1

def getAllCosts(arr, N, X):
    rtn = []
    for index in range(N):
        ##print(index)
        ##narr = copy.copy(arr)
        ##print(fastCosts(index, arr, N, X))

        #rtn = elementWiseSum(rtn, fastCosts(index,arr, N, X))
        rtn.append(fastCosts(index,arr, N, X))
    ##print(rtn)
    return rtn

def buyop(rtn, N, X):
    total = 0
    indexesGot = dict()
    for element in rtn:
        total += min(element)
        try:
            indexesGot[element.index(min(element))] += 1
        except:
            indexesGot[element.index(min(element))] = 1
    keys = indexesGot.keys()
    remove = 0
    ## corrections to our summation
    for key in keys:
        if (key != max(keys)):
            remove += indexesGot[key] * key * X
        elif (key == max(keys)):
            remove += (indexesGot[key] - 1) * key * X



    return total - remove

t = getAllCosts(arr, N, X)
print(buyop(t, N, X))

Submission status: Wrong Answer

Solution code:
import math


N, X = map(int, input().split())
arr = list(map(int, input().split()))
"""
N, X = 2000, 1000
arr = []
for index in range(N):
    arr.append(randint(0,2000))
inventory = [] ## filled with indexes of arr to keep track
## im pretty sure that moving the prices is the same as moving the colour of the already had things
"""

## gaming time

def fastCosts(index, arr, N, X):
    ## dont I just need to add some constants to the list we already have
    costs = []
    ## what is each element of costs

    for counter in range(0, N):
        costs.append(arr[ (index+counter) % (N)] + counter*X)
    return costs

def elementWiseSum(list1, list2):
    if (len(list1) == 0):
        return list2
    if (len(list2) == 0):
        return list1
    for index in range(len(list1)):
        list1[index] += list2[index]
    return list1

def getAllCosts(arr, N, X):
    rtn = []
    for index in range(N):
        ##print(index)
        ##narr = copy.copy(arr)
        ##print(fastCosts(index, arr, N, X))

        #rtn = elementWiseSum(rtn, fastCosts(index,arr, N, X))
        rtn.append(fastCosts(index,arr, N, X))
    ##print(rtn)
    return rtn

def buyop(rtn, N, X):
    total = 0
    indexesGot = dict()
    for element in rtn:
        total += min(element)
        try:
            indexesGot[element.index(min(element))] += 1
        except:
            indexesGot[element.index(min(element))] = 1
    keys = indexesGot.keys()
    remove = 0
    ## corrections to our summation
    for key in keys:
        if (key != max(keys)):
            remove += indexesGot[key] * key * X
        elif (key == max(keys)):
            remove += (indexesGot[key] - 1) * key * X



    return total - remove

t = getAllCosts(arr, N, X)
print(buyop(t, N, X))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
h={i:False for i in range(n)}
t=0
while not all(h.values()):
  m,j=min((a[i],i) for i in range(n) if not h[i])
  mm=x+min(a[i] for i in range(n) if not h[(i-1)%n])
  if m<mm:
    h[j]=True
    t+=m
  else:
    h={i:h[(i-1)%n] for i in range(n)}
    t+=x
print(t)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
B = A * 2
for i in range(len(B)):
    B[i] += x * i
res = 0
dist = 0
for i in range(N):
    mi = 10**18
    pmi = -1
    for j in range(i, N*2):
        if mi > B[j]:
            mi = B[j]
            pmi = j
    res += A[pmi % N]
    dist = max(dist, pmi - i)
print(res + x * dist)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
B = A * 2
for i in range(len(B)):
    B[i] += x * i
res = 0
dist = 0
for i in range(N):
    id = B[i:].index(min(B[i:])) + i
    res += A[id % N]
    dist = max(dist, id - i)
print(res + x * dist)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
B = A * 2
for i in range(len(B)):
    B[i] += x * i
res = 0
dist = 0
for i in range(N):
    id = B.index(min(B[i:]))
    res += A[id % N]
    dist = max(dist, id - i)
print(res + x * dist)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split())) * 2
for i in range(len(A)):
    A[i] += x * i
res = 0
for i in range(N):
    res += min(A[i:]) - x * i    
print(res)