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 math

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

ans = 0
inds = []
for i in range(N): # to
    temp = 10 ** 20 #これは指標
    tempfrom = 0 # これは毎回足す
    tempind = 0 #これは格納しておいて一度に使う

    for j in range(N): # fromを一通り試す j番目の要素から
        # jからiへ向かう
        # i - j
        diff =  i - j
        if  diff < 0:
            diff %= N

        if temp >= diff * x + As[j]: # 元の生産コスト + toまでのコスト
            mindiff = diff
            temp = diff * x + As[j] #総コスト
            tempstart = As[j] #元の生産コスト
    ans += tempstart
    inds.append(mindiff)
ans += max(inds) * x
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0
inds = []
for i in range(N): # to
    temp = 10 ** 20 #これは指標
    tempfrom = 0 # これは毎回足す
    tempind = 0 #これは格納しておいて一度に使う

    for j in range(N): # fromを一通り試す
        index = i + j #fromのindex
        index %= N #indexの調整(くるっと周ったときの対策)

        if temp > j * x + As[index]: # 元の生産コスト + toまでのコスト
            tempind = j
            temp = j * x + As[index] #総コスト
            tempstart = As[index] #元の生産コスト
    ans += tempstart
    inds.append(tempind)
ans += max(inds) * x
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0
for i in range(N): # to
    temp = 10 ** 20 #これは指標
    tempfrom = 0 # これは毎回足す
    tempind = 0 #これは格納しておいて一度に使う
    inds = []
    for j in range(N): # fromを一通り試す
        index = i + j #fromのindex
        index %= N #indexの調整(くるっと周ったときの対策)

        if temp > j * x + As[index]: # 元の生産コスト + toまでのコスト
            tempind = j
            temp = j * x + As[index] #総コスト
            tempstart = As[index] #元の生産コスト
    ans += tempstart
    inds.append(tempind)
ans += max(inds) * x
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0
for i in range(N): # to
    temp = 10 ** 10 #これは指標
    tempfrom = 0 # これは毎回足す
    tempind = 0 #これは格納しておいて一度に使う
    inds = []
    for j in range(N): # fromを一通り試す
        index = i + j #fromのindex
        index %= N #indexの調整(くるっと周ったときの対策)

        if temp > j * x + As[index]: # 元の生産コスト + toまでのコスト
            tempind = j
            temp = j * x + As[index] #総コスト
            tempstart = As[index] #元の生産コスト
    ans += tempstart
    inds.append(tempind)
ans += max(inds) * x
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
As = list(map(int, input().split()))
js = [-1]*N
ds = [-1]*N
for i in range(N):
  j = min(range(N), key=lambda j: As[j]+x*((j-i)%N))
  js[i] = j
  ds[i] = (j-i)%N
r = sum([As[j] for j in js])+max(ds)*x
print(r)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
_A = A[A.index(min(A)):] + A[0:A.index(min(A))]
L = [0] * N
for i in range(1, N):
  if (_A[i - 1 - L[i - 1]] + x) * (L[i - 1] + 1) <= _A[i]:
    L[i] = L[i - 1] + 1
    _A[i] = (_A[i - L[i]] + x) * L[i]
cnt = 0
for i in range(N):
  cnt += _A[i - L[i]]
cnt += x * max(L)
print(cnt)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
_A = A[A.index(min(A)):] + A[0:A.index(min(A))]
L = [0] * N
for i in range(1, N):
  if (_A[i - 1 - L[i - 1]] + x) * (L[i] + 1) <= _A[i]:
    L[i] = L[i - 1] + 1
    _A[i] = (_A[i - L[i]] + x) * L[i]
cnt = 0
for i in range(N):
  cnt += _A[i - L[i]]
cnt += x * max(L)
print(cnt)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
_A = A[A.index(min(A)):] + A[0:A.index(min(A))]
L = [0] * N
for i in range(1, N):
  if _A[i - 1] + x <= _A[i]:
    L[i] = L[i - 1] + 1
    _A[i] = _A[i - 1] + x
cnt = 0
for i in range(N):
  cnt += _A[i - L[i]]
cnt += x * max(L)
print(cnt)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
_A = A + A
L = [0] * N
for i in range(1, 2 * N):
  if _A[i - 1] + x <= _A[i]:
    L[i % N] = L[(i - 1) % N] + 1
    _A[i] = _A[i - 1] + x
cnt = 0
for i in range(N):
  cnt += A[(i - L[i]) % N]
cnt += x * max(L)
print(cnt)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[int(j) for j in input().split()]
l=[]
ll=[]
for i in range(n):
    tmp=a[i]
    tmp2=0
    tmp3=a[i]
    for j in range(n):
        if i>=j:
            if tmp>a[j]+x*(i-j):
                tmp=a[j]+x*(i-j)
                tmp3=a[j]
                tmp2=i-j
            if tmp==a[j]+x*(i-j):
                if tmp2<i-j:
                    tmp=a[j]+x*(i-j)
                    tmp3=a[j]
                    tmp2=i-j
        else:
            if tmp>a[j]+x*(n+i-j):
                tmp3=a[j]
                tmp2=n+i-j
                tmp=a[j]+x*(n+i-j)
            if tmp==a[j]+x*(n+i-j):
                if tmp2<n+i-j:
                    tmp3=a[j]
                    tmp2=n+i-j
                    tmp=a[j]+x*(n+i-j)
    l.append(tmp3)
    ll.append(tmp2)

print(sum(l)+x*max(ll))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[int(j) for j in input().split()]
l=[]
ll=[]
for i in range(n):
    tmp=a[i]
    tmp2=10**100
    tmp3=a[i]
    for j in range(n):
        if i>=j:
            if tmp>=a[j]+x*(i-j):
                tmp=a[j]+x*(i-j)
                tmp3=a[j]
                tmp2=i-j
        else:
            if tmp>=a[j]+x*(n+i-j):
                tmp3=a[j]
                tmp2=n+i-j
                tmp=a[j]+x*(n+i-j)
    l.append(tmp3)
    ll.append(tmp2)

print(sum(l)+x*max(ll))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[int(j) for j in input().split()]
l=[]
ll=[]
for i in range(n):
    tmp=a[i]
    tmp2=0
    for j in range(n):
        if i>=j:
            if tmp>a[j]+x*(i-j):
                tmp=a[j]
                tmp2=i-j
            if tmp==a[j]+x*(i-j):
                tmp2=min(tmp2,i-j)
        else:
            if tmp>a[j]+x*(n+i-j):
                tmp=a[j]
                tmp2=n+i-j
            if tmp==a[j]+x*(n+i-j):
                tmp2=min(tmp2,n+i-j)
    l.append(tmp)
    ll.append(tmp2)

print(sum(l)+x*max(ll))

Submission status: Wrong Answer

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

dp_list = [ 10**10 for i in range(n) ]
ans_list = [ None for i in range(n) ]
for i in range(n):
    new_dp_list = [ 10**10 for i in range(n) ]
    c = color_list[i]
    for j in range(n):
        a = (i+j)%n
        if c + x*j < dp_list[a]:
            new_dp_list[a] = c + x*j
            ans_list[a] = (c,j)
        elif c+ x*j == dp_list[a] and ans_list[a] is not None:
            if j > ans_list[a][1]:
                ans_list[a] = (c,j)
            new_dp_list[a] = dp_list[a]
        else:
            new_dp_list[a] = dp_list[a]
    dp_list = new_dp_list

y, z = zip(*ans_list)
print(sum(y)+x*max(z))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,c = LI()
    if (not a%2) or (not b%2) or (not c%2):
        print(0)
    else:
        print(min(a*b, b*c, c*a))
    return

#B
def B():
    n,x = LI()
    a = LI()
    m = min(a)
    f = [[a[i],i] for i in range(n)]
    for i in range(n):
        for j in range(n):
            ni = i-j
            if ni < 0:
                ni += n
            k = a[ni]+j*x
            if k < f[i][0]:
                f[i][0] = k
                f[i][1] = ni
    ans = [0]*n
    k = [0]*n
    for l in range(n):
        i,j = f[l]
        ans[j] = max(ans[j],i)
        if l != j:
            k[j] += a[j]
    print(sum(ans)+sum(k))
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,c = LI()
    if (not a%2) or (not b%2) or (not c%2):
        print(0)
    else:
        print(min(a*b, b*c, c*a))
    return

#B
def B():
    n,x = LI()
    a = LI()
    m = min(a)
    f = [[a[i],i] for i in range(n)]
    for i in range(n):
        for j in range(n):
            ni = i-j
            if ni < 0:
                ni += n
            k = (j+1)*a[ni]+j*x
            if k < f[i][0]:
                f[i][0] = k
                f[i][1] = ni
    ans = [0]*n
    for i,j in f:
        ans[j] = max(ans[j],i)
    print(sum(ans))
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,c = LI()
    if (not a%2) or (not b%2) or (not c%2):
        print(0)
    else:
        print(min(a*b, b*c, c*a))
    return

#B
def B():
    n,x = LI()
    a = LI()
    m = min(a)
    f = [[a[i],i] for i in range(n)]
    for i in range(n):
        for j in range(n):
            ni = i-j
            if ni < 0:
                ni += n
            k = a[ni]+j*x+j
            if k < f[i][0]:
                f[i][0] = k
                f[i][1] = ni
    ans = [0]*n
    for i,j in f:
        ans[j] = max(ans[j],i)
    print(sum(ans))
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

"""
各スライム（最終状態）に対して、どこで生産すればよかったか。
操作2の回数を決めるごとに計算できる。
"""

N,X = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)

AA = np.concatenate([A,A])

answer = AA[N:].sum()
for n in range(1,N+1):
    np.minimum(AA[1:],AA[:-1],out=AA[1:])
    answer = min(answer, AA[N:].sum()+X*n)

print(answer)

Submission status: Wrong Answer

Solution code:
prev=lambda n,i,d: i-d if i-d>=0 else n+i-d
N,x=map(int,input().split())
A=list(map(int,input().split()))
dp = A[:]
ans=int(10**10)
for d in range(N):
    for i in range(N):
        p = prev(N,i,d)
        dp[i]=min(dp[i], A[p])
    ans=min(ans,sum(dp)+d*x)
print(ans)

Submission status: Wrong Answer

Solution code:
n,x,*a = map(int,open(0).read().split())
ref = [10e9]*n
ans = 10e9
for i in range(n):
	ref = [min(ref[j],a[(j+i)%n]) for j in range(n)]
	ans = min(ans,sum(ref)+i*x)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def sol():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    minCatch = 0
    for i, a in enumerate(A):
        if A[minCatch] > a:
            minCatch = i

    magicCount = [0] * N
    minCost = [float('inf')] * N
    minCost[minCatch] = A[minCatch]

    for i in range(minCatch + 1, N):
        if A[i] > minCost[i - 1] + X:
            minCost[i] = minCost[i - 1] + X
            magicCount[i] = magicCount[i - 1] + 1
        else:
            minCost[i] = A[i]
            magicCount[i] = 0
    for i in range(minCatch):
        if A[i] > minCost[i - 1] + X:
            minCost[i] = minCost[i - 1] + X
            magicCount[i] = magicCount[i - 1] + 1
        else:
            minCost[i] = A[i]
            magicCount[i] = 0

    ans = 0
    for cost, magic in zip(minCost, magicCount):
        ans += cost - magic * X
    ans += max(magicCount) * X
    print(ans)

sol()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def sol():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    minCatch = 0
    for i, a in enumerate(A):
        if A[minCatch] > a:
            minCatch = i

    magicCount = [0] * N
    minCost = [float('inf')] * N
    minCost[minCatch] = A[minCatch]

    for i in range(1, N + 1):
        j = (i + minCatch) % N
        if A[j] > minCost[j - 1] + X:
            minCost[j] = minCost[j - 1] + X
            magicCount[j] = magicCount[j - 1] + 1
        else:
            minCost[j] = A[j]
            magicCount[j] = 0

    ans = 0
    for cost, magic in zip(minCost, magicCount):
        ans += cost - magic * X
    ans += max(magicCount) * X
    print(ans)

sol()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

N, x = map(int, input().split())
A = list(map(int, input().split()))
ans, M = 0, 0
for i, a in enumerate(A):
    C = [(a+x*(i-j), a, i-j) for j, a in enumerate(A[:i])] + [(a, a, 0)] + [(a+x*(N-j), a, N-j) for j, a in enumerate(A[i+1:], 1)]
    c = min(C, key = lambda v: v[0])
    ans += c[1]
    M = max(M, c[2])
print(ans+M*x)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

N, x = map(int, input().split())
A = list(map(int, input().split()))
ans, M = 0, 0
for i, a in enumerate(A):
    C = [(a+x*(i-j), a, i-j) for j, a in enumerate(A[:i])] + [(a, a, 0)] + [(a+x*(i+N-j), a, i+N-j) for j, a in enumerate(A[i+1:], 1)]
    c = min(C, key = lambda v: v[0])
    ans += c[1]
    M = max(M, c[2])
print(ans+M*x)

Submission status: Wrong Answer

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))

# dp[i]: i 色のスライムを捕まえるコスト
dp = A[:]
# xs[i]: i にするまでに色を変える回数
xs = [0] * N
for i in range(N ** 2):
    i = i % N
    j = (i + 1) % N
    if dp[i] + xs[i] * X + X <= dp[j] + xs[j] * X:
        dp[j] = dp[i]
        xs[j] = xs[i] + 1
# いい感じに順番をつければ色変えは最大 xs.max() 回でいい
ans = sum(dp) + max(xs) * X
print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))

# dp[i]: i 色のスライムを捕まえるコスト
dp = A[:]
# xs[i]: i にするまでに色を変える回数
xs = [0] * N
for i in range(N ** 2):
    i = i % N
    j = (i + 1) % N
    if dp[i] + xs[i] * X + X < dp[j] + xs[j] * X:
        dp[j] = dp[i]
        xs[j] = xs[i] + 1
# いい感じに順番をつければ色変えは最大 xs.max() 回でいい
ans = sum(dp) + max(xs) * X
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))

# dp[i]: i 色のスライムを捕まえるコスト
dp = np.array(A, dtype=int)
# xs[i]: i にするまでに色を変える回数
xs = np.zeros(N, dtype=int)
for i in range(N * 3):
    i = i % N
    j = (i + 1) % N
    if dp[i] + xs[i] * X + X < dp[j] + xs[j] * X:
        dp[j] = dp[i]
        xs[j] = xs[i] + 1
# いい感じに順番をつければ色変えは最大 xs.max() 回でいい
ans = dp.sum() + xs.max() * X
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))

# dp[i]: i 色のスライムを捕まえるコスト
dp = np.array(A, dtype=int)
# xs[i]: i にするまでに色を変える回数
xs = np.zeros(N, dtype=int)
for i in range(N):
    j = (i + 1) % N
    if dp[i] + xs[i] * X + X < dp[j] + xs[j] * X:
        dp[j] = dp[i]
        xs[j] = xs[i] + 1
# いい感じに順番をつければ色変えは最大 xs.max() 回でいい
ans = dp.sum() + xs.max() * X
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
m=a.index(min(a))
a=a[m:]+a[:m]
sorta=[i for i,t in enumerate(a)]
a=[[i,False] for i in a]
ans=10**14
for p in sorta:
	a[p][1]=True
	temp=0
	maxx=0
	cnt=0
	for i,j in a:
		if j:
			now=i
			m=max(maxx,cnt)
			cnt=0
		else:
			cnt+=1
		temp+=now
	maxx=max(maxx,cnt)
	temp+=x*maxx
	ans=min(ans,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
A=[[i,i,0] for i in a]
b=[]

m=0
while(b!=A):
    b=dc(A)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if A[i][1]!=A[j][1]:
                if a[i]>=A[j][1]+x or (a[i]>=A[j][1] and A[j][2]<m):
                    A[i][0]=A[j][1]+x
                    A[i][1]=A[j][1]
                    A[i][2]=A[j][2]+1
    for i in A:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in A:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
aa=dc(a)
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if aa[i][0]>=a[j][1]+x or (aa[i][0]>=a[j][1] and a[j][2]<m):
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)
#print(a)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if a[i][0]>=a[j][1]+x or (a[i][0]>=a[j][1] and a[j][2]<m):
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if a[i][0]>a[j][1]+x or (a[i][0]>=a[j][1] and a[j][2]<m):
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if a[i][0]>a[j][1]+x or (a[i][0]>=a[j][1] and a[i][2]<m):
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if a[i][0]>a[j][1]+x:
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if a[i][0]>=a[j][1]+x or (a[i][0]>=x and a[i][2]<m):
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][1]!=a[j][1]:
                if a[i][0]>a[j][1]+x or (a[i][0]>=x and a[i][2]<m):
                    a[i][0]=a[j][1]+x
                    a[i][1]=a[j][1]
                    a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy as dc
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
b=[]

m=0
while(b!=a):
    b=dc(a)
    for _ in range(2):
        for i in range(n):
            j=i-1
            if j==-1:
                j=n-1
            if a[i][0]>a[j][1]+x or (a[i][0]>x and a[i][2]<m):
                a[i][0]=a[j][1]+x
                a[i][1]=a[j][1]
                a[i][2]=a[j][2]+1
    for i in a:
        m=max(i[2],m)
        
s=0
s+=m*x
for i in a:
    s+=i[1]
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
for _ in range(2):
    for i in range(n):
        j=i-1
        if j==-1:
            j=n-1
        if a[i][0]>a[j][1]+x:
            a[i][0]=a[j][1]+x
            a[i][1]=a[j][1]
            a[i][2]=a[j][2]+1

m=0
s=0
for i in a:
    m=max(i[2],m)
    s+=i[1]
s+=m*x
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
for _ in range(2):
    for i in range(n):
        j=i-1
        if j==-1:
            j=n-1
        if a[i][0]>a[j][0]+x:
            a[i][0]=a[j][0]+x
            a[i][1]=a[j][1]
            a[i][2]=a[j][2]+1

m=0
s=0
for i in a:
    m=max(i[2],m)
    s+=i[1]
s+=m*x
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
for _ in range(n+1000):
    for i in range(n):
        j=i-1
        if j==-1:
            j=n-1
        if a[i][0]>a[j][0]+x:
            a[i][0]=a[j][0]+x
            a[i][1]=a[j][1]
            a[i][2]=a[j][2]+1

m=0
s=0
for i in a:
    m=max(i[2],m)
    s+=i[1]
s+=m*x
print(s)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=[[i,i,0] for i in a]
for _ in range(n):
    for i in range(n):
        j=i-1
        if j==-1:
            j=n-1
        if a[i][0]>a[j][0]+x:
            a[i][0]=a[j][0]+x
            a[i][1]=a[j][1]
            a[i][2]=a[j][2]+1

m=0
s=0
for i in a:
    m=max(i[2],m)
    s+=i[1]
s+=m*x
print(s)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
m=a.index(min(a))
a=a[m:]+a[:m]
c=[[10**9]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if j==0:
            c[j][i]=a[i]
        elif i<j:
            c[j][i]=c[j-1][i]
        else:
            c[j][i]=c[j-1][i-1] if c[j-1][i-1]+x*i<a[i] else a[i]
ans=2*10**12
for i in range(N):
    ans=min(ans,sum(c[i])+x*i)
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))
l_val=[[0,0,0]]*n
ind=l.index(min(l))
l=l[ind:]+l[:ind]
l_val[0]=[l[0],l[0],0]
for i in range(n-1):
    if l[i+1]>l_val[i][0]+x:
        l_val[i+1]=[l_val[i][0]+x,l_val[i][1],l_val[i][2]+1]
    else:
        l_val[i+1]=[l[i+1],l[i+1],0]
print(sum([i[1] for i in l_val])+max([i[2] for i in l_val])*x)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split()) # 横に2個
A = list(map(int, input().split()))


ans = 0
curll = []
for i, a in enumerate(A):
    k = a
    ind = i
    curl = False
    count = 0
    cost = a
    minc = 0
    while k > 0 or count < N:
        count += 1
        if ind == N-1:
            ind = 0
        else:
            ind += 1
        if k > A[ind] + x:
            cost0 = A[ind] + x*count
            if cost0 < cost:
                cost = cost0
                minc = count
            curl = True
        k -= x
    if not curl:
        ans += a
    else:
        ans += cost - x*minc
        curll.append(minc)

if curll:
    ans += max(curll)*x

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))
    ans = sum(A)
    for i in range(1, N):
        for j in range(N, 0, -1):
            A[j % N] = min(A[j % N], A[(j-1) % N])
        ans = min(ans, sum(A) + i * x)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N, x = map(int, input().split())
a = list(map(int, input().split()))
min_num = min(a)
b = [a[i] - (x + min_num) for i in range(N)]

for i in range(N):
    if b[i] <= 0:
        b[i] = a[i]
    else:
        b[i] = x + min_num
print(sum(b))

Submission status: Wrong Answer

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

ans = 0

X = [[0] for i in range(N)]

for i in range(N) :
    L = []
    for j in range(N) :
        a = A[j]
        calc = a + x * ((i+N-j) % N)
        L.append(calc)
    
    mi = min(L)
    
    ind = L.index(mi)
    
    X[ind].append(mi)

for x in X :
    ans += max(0, max(x) + len(x) - 2)

print(ans)