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:
num, change_duration = tuple([ int(x) for x in raw_input().split() ])
get_durations = tuple([ int(x) for x in raw_input().split() ])

def solve(num, change_duration, get_durations):
    change_num = 0
    min_duration = min(get_durations)
    min_index = get_durations.index(min_duration)
    get_times = [0] * num
    change_nums = [0] * num
    for count in xrange(num):
        if count == 0:
            get_times[min_index] = min_duration
            continue
        index = min_index + count
        if index >= num:
            index -= num
        gd = get_durations[index]
        prev_gd = get_times[index-1]
        if prev_gd + change_duration <= gd:
            change_nums[index] = change_nums[index-1]+1
            get_times[index] = prev_gd
        else:
            get_times[index] = gd
    max_change_num  =max(change_nums)
    all_change_time = max_change_num * change_duration
    if max_change_num > 0:
        for count in xrange(num):
            if count == 0:
                get_times[min_index] = min_duration
                continue
            index = min_index + count
            if index >= num:
                index -= num
            gd = get_times[index]
            temp_index = index - max_change_num
            if abs(temp_index) > num:
                temp_index += num
            candidates = get_durations[temp_index:index+1]
            if len(candidates) > 0:
                get_times[index] = min(candidates)
    all_get_time = sum(get_times)
    return all_get_time + all_change_time

print solve(num, change_duration, get_durations)

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_index = a.index(min(a))
index_list = list(range(min_index,N)) + list(range(min_index))
cost = a
c_count = [0]*N
for i in range(1,N):
    if cost[index_list[i]] > (cost[index_list[i-1]]+x):
        cost[index_list[i]] = cost[index_list[i-1]]+x
        c_count[index_list[i]] = c_count[index_list[i-1]]+1

print(sum(cost) )

Submission status: Wrong Answer

Solution code:
colors,magic = (int(n) for n in input().split(' '))
times = [int(n) for n in input().split(' ')]
ans = [0 for n in range(colors)]
sumit = 0
magicnt = {}
maxmagic = {}
for m in range(colors):
    tempans = float("inf")
    tempmag = 0
    for n in range(colors):
        if magic > times[m]:
            break
        elif n == m:
            continue
            #tempans = min(tempans,times[n])
        else:
            if tempans > times[n] + magic * ((m - n) % colors):
                tempmag = n
                tempans = times[n] + magic * ((m - n) % colors)
    if times[m] < tempans:
        sumit += times[m]
    else:
        magicnt[tempmag] = magicnt.get(tempmag,0) + 1
        maxmagic[tempmag] = max(tempans,maxmagic.get(tempmag,0))

for ind,value in magicnt.items():
    sumit += (times[ind]) * (value - 1)
for value in maxmagic.keys():
    sumit += maxmagic[value]

print(sumit)

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
s=[0]*n
while 0 in s:
    for i in xrange(n):
        if a[i]<=x and s[i]==0:
            ans+=a[i]
            s[i]+=1
    if 0 in s:
        news=[0]*n
        ans+=x
        for i in xrange(n):
            if s[i]==1:
                if i==n-1:
                    news[0]+=1
                else:
                    news[i+1]+=1
        s=news
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

line1 = raw_input().split()
line2 = [int(ai) for ai in raw_input().split()]

N = int(line1[0])
x = int(line1[1])

caught = [False] * N
time = 0

# FUNCTIONS

def catch_fast_ones():
    global N, x, line2, caught, time
    A = list(line2)
    while (min(A) < x):
        current_minimum = min(A)
        indices = [i for i, value in enumerate(line2) if value == current_minimum]

        already_caught_all = True

        for ind in indices:
            if not caught[ind]:
                already_caught_all = False
                break

        if not already_caught_all:
            occurrences = line2.count(current_minimum)
            time += (current_minimum * occurrences)

            for ind in indices:
                caught[ind] = True

        while (current_minimum in A):
            A.remove(current_minimum)


def cast_spell():
    global N, x, line2, caught, time
    time += x
    items = deque(caught)
    items.rotate(1)
    caught = list(items)


def all_caught():
    global N, x, line2, caught, time
    for value in caught:
        if not value:
            return False
    return True


def catch_all():
    global N, x, line2, caught, time
    for i in range(N):
        time += line2[i]

# MAIN:

if max(line2) < x:
    catch_all()
else:
    while not all_caught():
        catch_fast_ones()
        if not all_caught():
            cast_spell()

print time

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_index = a.index(min(a))
index_list = list(range(min_index,N)) + list(range(min_index))
cost = a
c_count = [0]*N
s_count = [0]*N
s_count[index_list[0]] = 1
for i in range(1,N):
    if cost[index_list[i]] > (cost[index_list[i-1]]+x):
        cost[index_list[i]] = (cost[index_list[i-1]]+x)
        c_count[index_list[i]] = c_count[index_list[i-1]]+1

print(sum(cost) - (sum(c_count)*x) + ((len(c_count)-c_count.count(0))*x)  )

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
s=[0]*n
while 0 in s:
    for i in xrange(n):
        if a[i]<=x and s[i]==0:
            ans+=a[i]
            s[i]+=1
    if 0 in s:
        news=[0]*n
        ans+=x
        for i in xrange(n):
            if s[i]==1:
                if i==n-1:
                    news[0]+=1
                else:
                    news[i+1]=+1
        s=news
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
l = [1]*len(a)
ans = 0
for i in range(len(a)):
    for j in range(1, len(a)):
        if a[i]+x*j < a[(i+j)%len(a)]:
            l[i] = j+1
            
for i in range(len(a)):
    if l[i] > 1:
        for j in range(1, l[i]):
            l[(i+j)%len(a)] = 0
for i in range(len(a)):
    ans += a[i] * l[i]
print(ans + (max(l)-1) * x)

Submission status: Wrong Answer

Solution code:
import numpy as np

a = map(int,raw_input().split())
N = a[0]
x = a[1]
A = map(int,raw_input().split())

#st = time.time()
#N = 2000
#m = 1000000000
#x = np.random.randint(m)
#A = np.random.randint(m,size=(N))

B = np.zeros(N)
E = np.zeros(N)
#C = 10000000000*np.ones((N,N))
C = np.zeros((N,N))
for idx in xrange(N):
  C[idx] = np.array([A[idx-i]+x*i for i in range(N)])
  i = np.where(C[idx]==min(C[idx]))[0][0]
  B[idx] = A[idx-i]
  E[idx] = i

print int(sum(B)+max(E)*x)

Submission status: Wrong Answer

Solution code:
import numpy as np

a = map(int,raw_input().split())
N = a[0]
x = a[1]
A = map(int,raw_input().split())

#st = time.time()
#N = 2000
#m = 1000000000
#x = np.random.randint(m)
#A = np.random.randint(m,size=(N))

B = np.zeros(N)
E = np.zeros(N)
C = 10000000000*np.ones((N,N))
for idx in xrange(N):
  i = 0
  while x*i < A[idx] and i < N:
    C[idx][i] = A[idx-i]+x*i
    i += 1
  i = np.where(C[idx]==min(C[idx]))[0][0]
  B[idx] = A[idx-i]
  E[idx] = i

print int(sum(B)+max(E)*x)

Submission status: Wrong Answer

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

res = 0
magic = 0

i = 0
while i < N:
    counti = 2000
    geti = 0
    tmpcount = 0
    j = 0
    while j < N:
        if(i < j):
            tmpcount = N - j + i
        else:
            tmpcount = i - j
        if tmpcount < counti:
            counti = tmpcount
            geti = j
        j += 1
    res += a[geti]
    magic = max(counti, magic)
    
    i += 1

res += magic * x

print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np

a = map(int,raw_input().split())
N = a[0]
x = a[1]
A = map(int,raw_input().split())

#st = time.time()
#N = 2000
#m = 1000000000
#x = np.random.randint(m)
#A = np.random.randint(m,size=(N))

B = np.zeros(N)
E = np.zeros(N)
C = 10000000000*np.ones((N,N))
for idx in xrange(N):
  i = 0
  while x*i < A[idx]:
    C[idx][i] = A[idx-i]+x*i
    i += 1
  i = np.where(C[idx]==min(C[idx]))[0][0]
  B[idx] = A[idx-i]
  E[idx] = i

print int(sum(B)+max(E)*x)
#print time.time() - st

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, x = (int(_) for _ in input().split(' '))
    As = [int(_) for _ in input().split(' ')]
    low = As.index(min(As))
    t = 0
    for i in range(N):
        if low < i:
            draw = i - low
        else:
            draw = (N - low) + i
        t += min(As[i], 1 + draw * x)
    print(t)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, x = map(int, input().split())
bs = np.array(list(map(int, input().split())))
bb = np.hstack((bs, bs))

s = 0
maxn = 0
for i in range(len(bs)):
    d = bs[i] // x
    m = bs[i]
    minb = bs[i]
    for n in range(1, min(N, d)+1):
        if bs[i-n] + n*x < m:
            m = bs[i-n] + n*x
            minb = bs[i-n]
            if maxn < n:
                maxn = n
    s += minb
s += maxn * x

print(int(s))

Submission status: Wrong Answer

Solution code:
def inp():
    return int(raw_input())
def linp():
    return map(int, raw_input().split())
n, x = linp()
li=linp()
lis=[]
for i in xrange(n):
    lis.append((li[i]+x))
ans=0
for i in xrange(n):
    ans+=min(li[i], min(lis))
print ans

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, x = (int(_) for _ in input().split(' '))
    As = [int(_) for _ in input().split(' ')]
    low = As.index(min(As))
    t = 0
    for i in range(N):
        t += min(As[i], 1 + abs(i - low) * x)
    print(t)

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_index = a.index(min(a))
index_list = list(range(min_index,N)) + list(range(min_index))
cost = a
c_count = [0]*N
s_count = [0]*N
s_count[index_list[0]] = 1
for i in range(1,N):
    if cost[index_list[i]] > (cost[index_list[i-1]]+x):
        cost[index_list[i]] = (cost[index_list[i-1]]+x)
        c_count[index_list[i]] = c_count[index_list[i-1]]+1

print(sum(cost) - (sum(c_count)*x) + (max(c_count)*x)  )

Submission status: Wrong Answer

Solution code:
num, change_duration = tuple([ int(x) for x in raw_input().split() ])
get_durations = tuple([ int(x) for x in raw_input().split() ])

def solve(num, change_duration, get_durations):
    change_num = 0
    min_duration = min(get_durations)
    min_index = get_durations.index(min_duration)
    get_times = [0] * num
    change_nums = [0] * num
    for count in xrange(num):
        if count == 0:
            get_times[min_index] = min_duration
            continue
        index = min_index + count
        if index >= num:
            index -= num
        gd = get_durations[index]
        prev_gd = get_times[index-1]
        if prev_gd + change_duration <= gd:
            change_nums[index] = change_nums[index-1]+1
            get_times[index] = prev_gd
        else:
            get_times[index] = gd
    all_get_time = sum(get_times)
    all_change_time = max(change_nums) * change_duration
    return all_get_time + all_change_time

print solve(num, change_duration, get_durations)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
t = 0
s = 0
for i in range(N):
	k = min(int(a[i] / x), N)
	for j in range(1,k+1):
		if a[i] > a[i-j] + x * j:
			a[i] = a[i-j]
			s = max(s, j)
t = sum(a) + s * x
t = min(t, b[0] * N + x * N)
print(t)

Submission status: Wrong Answer

Solution code:
def solve():
    n, x = map(int, input().split())
    al = [int(i) for i in input().split()]
    minnum = min(al)
    minidx = al.index(minnum)
    al = al[minidx:] + al[:minidx]

    cnt = 0
    cntlist = [0 for i in range(n)]
    anlist = []
    anlist.append(minnum)
    mincost = minnum
    for i in range(1, n):
        cost = min(mincost + x, al[i])
        if (mincost + x) > al[i]:
            mincost = al[i]
            cnt = 0
            anlist.append(al[i])
        else:
            mincost = cost
            cnt += 1
        cntlist[i] = cnt

    ans = 0
    anidx = -1
    cnt = 0
    for i in range(n):
        if cntlist[i] == 0:
            if anidx >= 0:
                ans += anlist[anidx] * cnt
                anidx += 1
            else:
                anidx = 0
            cnt = 0
        cnt += 1
    else:
        ans += anlist[anidx] * cnt
        ans += max(cntlist) * x

    print(ans)

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    n,x=map(int,stdin.readline().split())
    cout=list(map(int,stdin.readline().split()))
    total=0
    nombreAttrape=[0]*n

    for i in range(n):
        depart=i
        minimum=cout[i]
        for j in range(1,n):
            indice=(i+j)%n
            nombre=n-j
            coutProchain=cout[indice]+x*nombre
            if minimum>coutProchain:
                depart=indice
                minimum=coutProchain
        nombreAttrape[depart]+=1

    nombreSort=max(nombreAttrape)-1
    for i in range(n):
        total+=cout[i]*nombreAttrape[i]
    total+=nombreSort*x

    print(total)
main()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, x = (int(_) for _ in input().split(' '))
    As = [int(_) for _ in input().split(' ')]
    t = 0
    for i in range(N):
        t += min(As[i], 1 + x * i)
    print(t)

Submission status: Wrong Answer

Solution code:
colors,magic = (int(n) for n in input().split(' '))
times = [int(n) for n in input().split(' ')]
ans = [0 for n in range(colors)]
sumit = 0
magicnt = {}
maxmagic = {}
for m in range(colors):
    tempans = float("inf")
    tempmag = 0
    for n in range(colors):
        if n == m:
            continue
            #tempans = min(tempans,times[n])
        else:
            if tempans > times[n] + magic * ((m - n) % colors):
                tempmag = n
                tempans = times[n] + magic * ((m - n) % colors)
    if times[m] < tempans:
        sumit += times[m]
    else:
        magicnt[tempmag] = magicnt.get(tempmag,0) + 1
        maxmagic[tempmag] = max(tempans,maxmagic.get(tempmag,0))       
        
for ind,value in magicnt.items():
    sumit += (times[ind]) * (value - 1)
for value in maxmagic.values():
    sumit += value

print(sumit)

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = a[:]
ma = 0
for j in xrange(n):
    # print " j aj",j,a[j]
    for i in xrange(1,n):
        if a[j-i] + x*i < b[j]:
            # print "  swap", i,a[j-i]
            if i > ma:
                ma = i
                # print "   ma",ma
            b[j] = a[j-i]

print sum(b) + x * ma

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
A = map(int, raw_input().split())
ans = 0
mcnt = 0
for i in xrange(n):
    res = A[i]
    s = A[i]
    for j in xrange(n):
        tmp = A[i-j] + x*j
        if tmp < res:
            mcnt = max(mcnt, j)
            res = tmp
            s = A[i-j]
    ans += s
print ans + mcnt*x

Submission status: Wrong Answer

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

exceed_x = []
for i, v in enumerate(a):
    if v > x:
        exceed_x.append((i, v))

if len(exceed_x) == 0:
    print(sum(a))
else:
    min_a = min(a)
    min_i = a.index(min_a)
    result = N * min_a + len(exceed_x) * x
    print(result)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, x = (int(_) for _ in input().split(' '))
    As = (int(_) for _ in input().split(' '))
    t = 0
    for i in range(N):
        t += min(next(As), x + 1)
    print(t)

Submission status: Wrong Answer

Solution code:
def solve():
    n, x = map(int, input().split())
    al = [int(i) for i in input().split()]
    minnum = min(al)
    minidx = al.index(minnum)
    al = al[minidx:] + al[:minidx]

    cnt = 0
    cntlist = [0 for i in range(n)]
    anlist = []
    anlist.append(minnum)
    mincost = minnum
    for i in range(1, n):
        cost = min(mincost + x, al[i])
        if (mincost + x) >= al[i]:
            mincost = al[i]
            cnt = 0
            cntlist[i] = cnt
            anlist.append(al[i])
        else:
            mincost = cost
            cnt += 1
            cntlist[i] = cnt

    ans = 0
    anidx = -1
    cnt = 0
    for i in range(n):
        if cntlist[i] == 0:
            if anidx >= 0:
                ans += anlist[anidx] * cnt
                cnt = 0
                anidx += 1
            else:
                anidx = 0
                cnt = 0
        cnt += 1
    else:
        ans += anlist[anidx] * cnt
        ans += max(cntlist) * x

    print(ans)

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, x = (int(_) for _ in input().split(' '))
    As = [int(_) for _ in input().split(' ')]
    t = 0
    for i in range(N):
        t += min(As[i], x + 1)
    print(t)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import stdout

N,x = stdin.readline().split()
costs = map(int, stdin.readline().split())
avgx = float(x)/float(N)

startId = costs.index(min(costs))
realcosts = [0]* len(costs)
magiccount = [0]* len(costs)

realcosts[startId] = costs[startId]
magiccount[startId] = 0 
i = startId+1
while i!=startId:
        j = (i+int(N)-1)%int(N)
        if costs[i] < realcosts[j] + avgx*(magiccount[j]+1):
                realcosts[i] = costs[i]
                magiccount[i] = 0 
        else:
                realcosts[i] = realcosts[j]                                                                                                                          
                magiccount[i] = magiccount[j]+1
        i = (i +1)%int(N)

print sum(realcosts) + int(x) * max(magiccount)

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
min_index = a.index(min(a))
index_list = list(range(min_index,N)) + list(range(min_index))
cost = a
c_count = [0]*N
s_count = [0]*N
s_count[index_list[0]] = 1
for i in range(1,N):
    if cost[index_list[i]] > (cost[index_list[i-1]]+x):
        cost[index_list[i]] = (cost[index_list[i-1]]+x)
        c_count[index_list[i]] = c_count[index_list[i-1]]+1

print(sum(cost) - sum(c_count)*x + max(c_count)*x  )

Submission status: Wrong Answer

Solution code:
def solve():
	N,x = map(int,raw_input().split())
	a = map(int,raw_input().split())
	total_cost = 0
	max_move = 0
	for i in xrange(N):
		j = min(range(N),key=lambda mv:(a[(i-mv)%N]+mv*x,mv))
		total_cost += a[(i-j)%N]
		if j > max_move: max_move = j
	print total_cost + x*max_move
solve()

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = [(float('inf'), 0) for i in xrange(N)]

for i in xrange(N):
    for j in xrange(N):
        d = i - j if i >= j else i -j + N
        if a[j] + x*d <= b[i][0] + b[i][1]*x:
            b[i] = (a[j], d)

md = max([c[1] for c in b])
print sum([c[0] for c in b]) + md*x

Submission status: Wrong Answer

Solution code:
num, change_duration = tuple([ int(x) for x in raw_input().split() ])
get_durations = tuple([ int(x) for x in raw_input().split() ])

def solve(num, change_duration, get_durations):
    change_num = 0
    min_duration = min(get_durations)
    min_index = get_durations.index(min_duration)
    require_times = [0] * num
    get_times = [0] * num
    change_nums = [0] * num
    for count in xrange(num):
        if count == 0:
            get_times[min_index] = min_duration
            require_times[min_index] = min_duration
            continue
        index = min_index + count
        if index >= num:
            index -= num
        gd = get_durations[index]
        change_d = require_times[index-1] + change_duration
        if change_d <= gd:
            change_nums[index] = change_nums[index-1]+1
            temp_index = index-change_nums[index]
            if abs(temp_index) >= num:
                temp_index += num
            get_times[index] = get_durations[temp_index]
            require_times[index] = change_d
        else:
            get_times[index] = get_durations[index]
            require_times[index] = gd
    all_get_time = sum(get_times)
    all_change_time = max(change_nums) * change_duration
    return all_get_time + all_change_time

print solve(num, change_duration, get_durations)

Submission status: Wrong Answer

Solution code:
def solve():
    n, x = map(int, input().split())
    al = [int(i) for i in input().split()]
    minnum = min(al)
    minidx = al.index(minnum)
    al = al[minidx:] + al[:minidx]

    cnt = 0
    cntlist = [0 for i in range(n)]
    anlist = []
    anlist.append(minnum)
    mincost = minnum
    for i in range(1, n):
        cost = min(mincost + x, al[i])
        if cost == al[i]:
            mincost = al[i]
            cnt = 0
            cntlist[i] = cnt
            anlist.append(al[i])
        else:
            mincost = cost
            cnt += 1
            cntlist[i] = cnt

    ans = 0
    anidx = -1
    cnt = 0
    for i in range(n):
        if cntlist[i] == 0:
            if anidx >= 0:
                ans += anlist[anidx] * cnt
                cnt = 0
                anidx += 1
            else:
                anidx = 0
                cnt = 0
        cnt += 1
    else:
        ans += anlist[anidx] * cnt
        ans += max(cntlist) * x

    print(ans)

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np

a = map(int,raw_input().split())
N = a[0]
x = a[1]
A = map(int,raw_input().split())

B = np.zeros(N)
E = np.zeros(N)
D = np.zeros((N,N))
F = np.zeros((N,N))
for idx in xrange(len(A)):
  C = 10000000000*np.ones(N)
  for i in xrange(len(A)):
    if x*i >= A[idx]:
      break
    C[i] = A[idx-i]+x*i
    D[idx][i] = A[idx-i]
    F[idx][i] = i
  C = np.array(C)
  B[idx] = D[idx][np.where(C==min(C))[0][0]]
  E[idx] = F[idx][np.where(C==min(C))[0][0]]

print int(sum(B)+max(E)*x)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import itertools,math,bisect,pprint,sys
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
dp = a[:]
c = [0 for i in range(n)]
for i in range(n):
    if i<n-1:
        if dp[i]+x < dp[i+1]:
            c[i+1] += x
        dp[i+1] = min(dp[i]+x,dp[i+1])
    else:
        if dp[n-1]+x < dp[0]:
            c[0] += x
        dp[0] = min(dp[n-1]+x,dp[0])
print sum(dp)-sum(c)+max(c)

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
A = map(int, raw_input().split())
ans = 0
for i in xrange(n):
    res = A[i]
    for j in xrange(n):
        res = min(res, A[i-j] + x*j)
    ans += res
print ans

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
for i in xrange(n):
    time=float('inf')
    for j in xrange(n):
        if i>=j:
            time=min(time,a[j]+(i-j)*x)
        else:
            time=min(time,a[j]+(n-j+i)*x)
    ans+=time
print(ans)

Submission status: Wrong Answer

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

res = 0
magic = 0

for i in range(len(a)):
    sumi = 10 ** 18
    counti = 2000
    geti = 0
    tmpsum = 0
    tmpcount = 0
    for j in range(len(a)):
        if(i < j):
            tmpcount = (len(a) - j + i)
        else:
            tmpcount = i - j
        tmpsum = a[j] + tmpcount * x
        if tmpsum < sumi:
            sumi = tmpsum
            counti = tmpcount
            geti = j
    res += a[geti]
    magic = max(counti * x, magic)

res += magic

print(res)

Submission status: Wrong Answer

Solution code:
def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)

n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))

Submission status: Wrong Answer

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

check = [False] * N
ans = 0

while True:
    for i in range(N):
        if a[i] < x:
            check[i] = True
            ans += a[i]
    if (False in check) == False:
        print(ans)
        break

    temp = check[-1]
    for i in range(-1,-N,-1):
        check[i] = check[i-1]
    check[0] = temp
    ans += x
    if (False in check) == False:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = a[:]
ma = 0
for j in xrange(n):
    # print " j aj",j,a[j]
    for i in xrange(1,n):
        if a[j-i] + x*i < b[j]:
            # print "  swap", i,a[j-i]
            if i > ma:
                ma = i
                # print "   ma",ma
            b[j] = b[j-i]

print sum(b) + x * ma

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  4 21:22:58 2016

@author: you
"""

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

for i in range(len(a)):
    if a[i-1] + x < a[i] :
        a[i] = a[i-1] + x
for i in range(len(a)):
    if a[i-1] + x < a[i] :
        a[i] = a[i-1] + x

print(sum(a))

Submission status: Wrong Answer

Solution code:
num, change_duration = tuple([ int(x) for x in raw_input().split() ])
get_durations = tuple([ int(x) for x in raw_input().split() ])

def solve(num, change_duration, get_durations):
    change_num = 0
    min_duration = min(get_durations)
    min_index = get_durations.index(min_duration)
    require_times = [0] * num
    get_times = [0] * num
    change_nums = [0] * num
    for count in xrange(num):
        if count == 0:
            get_times[min_index] = min_duration
            require_times[min_index] = min_duration
            continue
        index = min_index + count
        if index >= num:
            index -= num
        gd = get_durations[index]
        change_d = require_times[index-1] + change_duration
        if change_d <= gd:
            change_nums[index] = change_nums[index-1]+1
            get_times[index] = get_durations[index-change_nums[index]]
            require_times[index] = change_d
        else:
            get_times[index] = get_durations[index]
            require_times[index] = gd
    all_get_time = sum(get_times)
    all_change_time = max(change_nums) * change_duration
    return all_get_time + all_change_time

print solve(num, change_duration, get_durations)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, x = (int(_) for _ in input().split(' '))
    As = (int(_) for _ in input().split(' '))
    each = sum(As)
    change = (N - 1) * x + N
    print(min(each, change))

Submission status: Wrong Answer

Solution code:
import numpy as np

a = map(int,raw_input().split())
N = a[0]
x = a[1]
A = map(int,raw_input().split())

B = np.zeros(N)
E = np.zeros(N)
D = []
for idx in xrange(len(A)):
  C = []
  D.append([])
  for i in xrange(len(A)):
    if x*i >= A[idx]:
      break
    C.append(A[idx-i]+x*i)
    D[idx].append([A[idx-i],i])
  C = np.array(C)
  B[idx] = D[idx][np.where(C==min(C))[0][0]][0]
  E[idx] = D[idx][np.where(C==min(C))[0][0]][1]

print int(sum(B)+max(E)*x)

Submission status: Wrong Answer

Solution code:
num, change_duration = tuple([ int(x) for x in raw_input().split() ])
get_durations = tuple([ int(x) for x in raw_input().split() ])

def solve(num, change_duration, get_durations):
    change_num = 0
    min_duration = min(get_durations)
    min_index = get_durations.index(min_duration)
    require_times = [0] * num
    get_times = [0] * num
    change_nums = [0] * num
    for count in xrange(num):
        if count == 0:
            get_times[min_index] = min_duration
            continue
        index = min_index + count
        if index >= num:
            index -= num
        gd = get_durations[index]
        change_d = require_times[index-1] + change_duration
        if change_d <= gd:
            change_nums[index] = change_nums[index-1]+1
            get_times[index] = get_durations[index-change_nums[index]]
            require_times[index] = change_d
        else:
            get_times[index] = get_durations[index]
            require_times[index] = gd
    all_get_time = sum(get_times)
    all_change_time = max(change_nums) * change_duration
    return all_get_time + all_change_time

print solve(num, change_duration, get_durations)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,x=map(int,stdin.readline().split())
cout=list(map(int,stdin.readline().split()))
indiceMin=0
for i in range(n):
    if cout[indiceMin]>cout[i]:
        indiceMin=i

total=0
for i in range(n):
    indice=(indiceMin+i)%n
    minimum=cout[indice]
    if indice!=indiceMin:
        minimum=min(minimum,cout[indiceMin]+x)
    total+=minimum
print(total)