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, raw_input().split())
l = map(int, raw_input().split())
p = l.index(min(l))
ll = l[p:] + l[:p]
m = 0
c = 0
t = ll[0]
ret = t
for i in range(1,n):
    if ll[i] <= ll[i-1]+x:
        t = ll[i]
        m = max(m,c)
        c = 0
    else:
        ll[i] = ll[i-1]+x
        c += 1
    ret += t
m = max(m,c)
print ret + m * x

Submission status: Wrong Answer

Solution code:
n,x = map(int, raw_input().split())
l = map(int, raw_input().split())
p = l.index(min(l))
ll = l[p:] + l[:p]
m = 0
c = 0
t = ll[0]
ret = t
for i in range(1,n):
    if ll[i] < ll[i-1]+x:
        t = ll[i]
        m = max(m,c)
        c = 0
    else:
        ll[i] = ll[i-1]+x
        c += 1
    ret += t
m = max(m,c)
print ret + m * x

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(zip(a, range(N)))[0][1]
l = a[b:] + a[:b]
maxcnt = 0
p = 0
cnt = 0
for i in range(N):
    if cnt == 0:
        k = 0
        l2 = [(N-y-i-1) * x  + (N-y-i+1) * l[y] for y in range(N-i)]
        for j in range(N-i):
            if l2[j] < l2[k]:
                k = j
        cnt = N-i-1 - k
        p += l[k]*(cnt+1)
        maxcnt = max(maxcnt, cnt)
    else:
        cnt -= 1
print(p + maxcnt * x)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(zip(a, range(N)))[0][1]
l = a[b:] + a[:b]
maxcnt = 0
p = 0
l2 = [l[i] + (N-i-1)*x for i in range(N)]

for i in range(N):
    k = 0
    l3 = [l2[y] + (N-y-1)*l[y] for y in range(N-i)]
    for j in range(N-i):
        if l3[j] < l3[k]:
            k = j
    p += l[k]
    maxcnt = max(maxcnt, N-i-1 - k)
print(p + maxcnt * x)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(zip(a, range(N)))[0][1]
l = a[b:] + a[:b]
maxcnt = 0
j = 0
cnt = 0
acnt = 0
bcnt = 0
p = l[0]
for i in range(1, N):
    if l[i] < l[j] + x + x * acnt:
        j = i
        maxcnt = max(cnt, maxcnt)
        bcnt = maxcnt
        p += l[j]
        cnt = 0
        acnt = 0
    else:
        if bcnt > 0:
            bcnt -= 1
        else:
            acnt += 1
        cnt += 1
        p += l[j]
maxcnt = max(cnt, maxcnt)
print(p + maxcnt * x)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(zip(a, range(N)))[0][1]
l = a[b:] + a[:b]
maxcnt = 0
j = 0
cnt = 0
acnt = 1
bcnt = 0
p = l[0]
for i in range(1, N):
    if l[i] < l[j] + x + x * acnt:
        j = i
        maxcnt = max(cnt, maxcnt)
        bcnt = maxcnt
        p += l[j]
        cnt = 0
        acnt = 0
    else:
        if bcnt > 0:
            bcnt -= 1
        else:
            acnt += 1
        cnt += 1
        p += l[j]
maxcnt = max(cnt, maxcnt)
print(p + maxcnt * x)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(zip(a, range(N)))[0][1]
l = a[b:] + a[:b]
maxcnt = 0
j = 0
cnt = 0
acnt = 1
bcnt = 0
p = l[0]
for i in range(1, N):
    if l[i] < l[j] + x * acnt:
        j = i
        maxcnt = max(cnt, maxcnt)
        bcnt = maxcnt
        p += l[j]
        cnt = 0
    else:
        if bcnt > 0:
            bcnt -= 1
        else:
            acnt += 1
        cnt += 1
        p += l[j]
maxcnt = max(cnt, maxcnt)
print(p + maxcnt * x)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(zip(a, range(N)))[0][1]
l = a[b:] + a[:b]
maxcnt = 0
j = 0
cnt = 0
acnt = 1
bcnt = 0
p = l[0]
for i in range(1, N):
    if l[i] < l[j] + x * acnt:
        j = i
        maxcnt = max(cnt, maxcnt)
        bcnt = maxcnt
        p += l[j]
    else:
        if bcnt > 0:
            bcnt -= 1
        else:
            acnt += 1
        cnt += 1
        p += l[j]
maxcnt = max(cnt, maxcnt)
print(p + maxcnt * x)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(zip(a, range(N)))[0][1]
l = a[b:] + a[:b]
maxcnt = 0
j = 0
cnt = 0
acnt = 1
bcnt = 0
p = l[0]
for i in range(1, N):
    if l[i] <= l[j] + x * acnt:
        j = i
        maxcnt = max(cnt, maxcnt)
        bcnt = maxcnt
        p += l[j]
    else:
        if bcnt > 0:
            bcnt -= 1
        else:
            acnt += 1
        cnt += 1
        p += l[j]
maxcnt = max(cnt, maxcnt)
print(p + maxcnt * x)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, x = map(int, input().split())
a = list(map(int, input().split()))
l = [1] * len(a)
t = x + min(a)
ans = 0
min_list = [x for x in range(N) if a[x] <= t]
if min_list:
    for i in min_list:
        l[i] = 0
        ans += a[i]
    while any(l):
        l = [l[-1]] + l[:-1]
        ans += x
        for i in min_list:
            if l[i]:
                l[i] = 0
                ans += a[i]
else:
    ans = sum(a)
print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
 
N, x = map(int, input().split())
a = list(map(int, input().split()))
l = [1] * len(a)
t = x + min(a)
ans = 0
min_list = [x for x in range(N) if a[x] <= t]
if min_list:
    # for i in min_list:
    #     l[i] = 0
    #     ans += a[i]
    # while any(l):
    #     l = [l[-1]] + l[:-1]
    #     ans += x
    #     for i in min_list:
    #         if l[i]:
    #             l[i] = 0
    #             ans += a[i]
    print(0)
else:
    ans = sum(a)
print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
 
N, X = map(int, input().split())
a = list(map(int, input().split()))
l = [1] * len(a)
ans = 0
min_list = [x for x in range(N) if a[x] < X]
if min_list:
    # for i in min_list:
    #     l[i] = 0
    #     ans += a[i]
    # while any(l):
    #     l = [l[-1]] + l[:-1]
    #     ans += X
    #     for i in min_list:
    #         if l[i]:
    #             l[i] = 0
    #             ans += a[i]
    print(0)
else:
    ans = sum(a)
print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, X = map(int, input().split())
a = list(map(int, input().split()))
l = [1] * len(a)
ans = 0
min_list = [x for x in range(N) if a[x] < X]
if min_list:
    for i in min_list:
        l[i] = 0
        ans += a[i]
    while any(l):
        l = [l[-1]] + l[:-1]
        ans += X
        for i in min_list:
            if l[i]:
                l[i] = 0
                ans += a[i]
else:
    ans = sum(a)
print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

N, X = map(int, input().split())
a = list(map(int, input().split()))
l = [1]*len(a)
ans = 0
min_list = [x for x in range(N) if a[x] < X]
for i in min_list:
    l[i] = 0
    ans += a[i]
while any(l):
    l = [l[-1]] + l[:-1]
    ans += X
    for i in min_list:
        if l[i]:
            l[i] = 0
            ans += a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
*A, = map(int, input().split())
a = min(A)
S = [x for x in range(N) if A[x] <= X + a]
B = [0] * N
ans = 0
for i in S:
    if B[i] == 0:
        ans += A[i]
        B[i] = 1
while not all(B):
    B = [B[-1]] + B[:-1]
    ans += X
    for i in S:
        if B[i] == 0:
            ans += A[i]
            B[i] = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
*A, = map(int, input().split())
n = 0
ans = 0
for i in range(N):
    
    if A[i] <= X:
        ans += A[i]
    else:
        a, b = sorted([(A[(i+N-x)%N]+X*x, x) for x in range(N)])[0]
        ans += a - X * b
        n = max(n, b)
ans += X * n
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
print(sorted(map(int, input().split()))[0]*N + x*(N-1))

Submission status: Wrong Answer

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


pos = a.index(min(a))
# print(pos)
b = [a[pos]] + a[pos+1:] + a[:pos]
# print(b)
ans = 0
n = len(a)

ans += b[0]
max_i = 0
for i in range(1, n):
    if b[i] >= b[0] * i * x:
        max_i = i
ans += max_i * x + max_i * b[0]
# print(max_i)
for i in range(max_i + 1, n):
    ans += b[i]
print(ans)

Submission status: Wrong Answer

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


pos = a.index(min(a))
# print(pos)
b = [a[pos]] + a[pos+1:] + a[:pos]
# print(b)
ans = 0
n = len(a)

ans += b[0]
max_i = 0
c = []
for i in range(1, n):
    if b[i] > b[0] * i * x:
        c.append(i)
        max_i = i
    else:
        ans += b[i]
ans += len(c) * x + len(c) * b[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split(" "))
a=map(int,raw_input().split(" "))
mi=[10**12]*n
ans=10**12
for m in range(n):
    mi=[min(mi[j],a[(j-m)%n]) for j in range(n)]
    ans=min(x*m+sum(mi),ans)
print ans

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split(" "))
a=map(int,raw_input().split(" "))
mi=[10**10]*n
ans=10**10
for m in range(n):
    mi=[min(mi[j],a[(j-m)%n]) for j in range(n)]
    ans=min(x*m+sum(mi),ans)
print ans

Submission status: Wrong Answer

Solution code:

N,x = map(int,input().split())

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

ans = sum(lst)

dp = lst

print(N,x)
print(lst)


for i in range(1,N):
    tmp = 0
    for k in range(0,N):
        index_ = 0
        if(0 <= k-i):
            index_ = k-i
        else:
            index_ = N-i+k
        dp[k] = min(dp[k],lst[index_])
        tmp = tmp+dp[k]
    tmp = tmp + x*i
    ans = min(ans,tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
A = map(int, raw_input().split())
A = A+A

b = [[A[i-j]+x*j for i in xrange(N,2*N)] for j in xrange(N)]
c = [list(min((bbb,i) for i,bbb in enumerate(bb))) for bb in b]

print sum(cc[0]-cc[1]*x for cc in c) + x * max(cc[1] for cc in c)

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
A = map(int, raw_input().split())
A = A+A

b = [[A[i-j]+x*j for i in range(N,2*N)] for j in range(N)]
c = [min(bb) for bb in b]
d = [bb.index(min(bb)) for bb in b]

print sum(c) - x * (sum(d)-max(d))

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = a[:]
ans = 10**12
for k in range(n):
    for i in range(n):
        b[i] = min(a[i-k],b[i])
    cost = k*x+sum(b)
    ans = min(ans,cost)
    if ans != cost:
        break
    if ans < (k+1)*x:
        break
print ans

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = a[:]
ans = 10**12
for k in range(n):
    for i in range(n):
        b[i] = min(a[i-k],b[i])
    cost = k*x+sum(b)
    if ans > cost:
        ans = cost
    else:
        break
    if ans < (k+1)*x:
        break
print ans

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
A = map(int, raw_input().split())
A = A+A


print sum([min([A[i-j]+x*j for i in range(N,2*N)]) for j in range(N)])

Submission status: Wrong Answer

Solution code:
import numpy as np


tflag = False
if tflag:
  N = 2000
  m = 1000000000
  x = np.random.randint(m)
  A = np.random.randint(m,size=(N))
#  st = time.time()
else:
  a = map(int,raw_input().split())
  N = a[0]
  x = a[1]
  A = map(int,raw_input().split())

maxa = max(A)
mina = min(A)
it = int(min((maxa-mina)/x+1,N))

E = np.zeros(it)
B = [A]
E[0] = sum(B[0])
for idx in xrange(1,it):
  B.append( [min(B[idx-1][i], A[i-idx]) for i in range(N)] )
  E[idx] = sum(B[idx])+idx*x

print int(min(E))

Submission status: Wrong Answer

Solution code:
import numpy as np


tflag = False
if tflag:
  N = 2000
  m = 1000000000
  x = np.random.randint(m)
  A = np.random.randint(m,size=(N))
#  st = time.time()
else:
  a = map(int,raw_input().split())
  N = a[0]
  x = a[1]
  A = map(int,raw_input().split())

maxa = max(A)
mina = min(A)
it = (maxa-mina)/x+1

E = np.zeros(it)
B = [A]
E[0] = sum(B[0])
for idx in xrange(1,it):
  B.append( [min(B[idx-1][i], A[i-idx]) for i in range(N)] )
  E[idx] = sum(B[idx])+idx*x

print int(min(E))

Submission status: Wrong Answer

Solution code:
import math

N, x = map(int, raw_input().split())
A = map(int, raw_input().split())
ans = 1e18
b = A
for k in range(N):
    sum = k*x
    for i in range(N):
        b[i] = min(b[i], A[(i+N-k)%N])
        sum += b[i]
    ans = min(ans, sum)
print ans

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a
cost = sum(s_cost)
for k in range(1,N):
    s_cost = [min(s_cost[x],s_cost[y]) for (x,y) in zip( list(range(N)), list(range(N-k,N))+list(range(N-k)) )]
    cost = min(cost, k*x + sum(s_cost))

print(cost)

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        i_list = list(range(i,N))+list(range(i))
        s_cost[i] = min(s_cost[i], s_cost[i_list[k]])
    cost = min(cost, k*x + sum(s_cost))

print(cost)

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.copy()
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) - sum(c_count)*x + max(c_count)*x  )

Submission status: Wrong Answer

Solution code:
import time
import numpy as np


tflag = False
if tflag:
  N = 2000
  m = 1000000000
  x = np.random.randint(m)
  A = np.random.randint(m,size=(N))
  st = time.time()
else:
  a = map(int,raw_input().split())
  N = a[0]
  x = a[1]
  A = map(int,raw_input().split())

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

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

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
max_time = 10**18

# 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)
            if time > max_time:
                return
            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
    if time > max_time:
        return
    items = deque(caught)
    items.rotate(1)
    caught = list(items)


def catch_all():
    global N, x, line2, caught, time
    for i in xrange(N):
        time += line2[i]
        if time > max_time:
            return

def catch_fastest_only():
    global N, x, line2, caught, time
    A = list(line2)
    while not all(caught):
        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:
            time += current_minimum
            if time > max_time:
                return
            caught[indices[0]] = True

        if not all(caught):
            cast_spell()

# MAIN:

if max(line2) < x:
    catch_all()
elif min(line2) > x:
    catch_fastest_only()
else:
    while not all(caught):
        if time > max_time:
            break
        catch_fast_ones()
        if not all(caught):
            cast_spell()

print time

Submission status: Wrong Answer

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

a = [[0 for i in range(N)] for j in range(N)]
count = 0

a[N-1][0] = A[N-1]

for i in range(N-1):
    a[i][0] = A[i]

    for j in range(N-1):
        a[i+1][j+1] = a[i][j] + x

for j in range(N-1):
    a[0][j+1] = a[N-1][j]

for i in range(N):
    count += min(a[i])


print int(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
A = map(int, raw_input().split())
import numpy as np

count = 0
a = np.zeros([N,N])
print a[1][0]
A = np.array(A)

a[N-1][0] = A[N-1]

for i in range(N-1):
    a[i][0] = A[i]
    print a
    for j in range(N-1):
        a[i+1][j+1] = a[i][j] + x
    
for j in range(N-1):
    a[0][j+1] = a[N-1][j]

for i in range(N):
    count += min(a[i])


print int(count)

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.copy()
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) - sum(c_count)*x + max(c_count)*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()]

#TLE!

res = 0
magic = 0

i = 0
while i < N:
    sumi = 10 ** 18
    counti = 2000
    geti = 0
    tmpsum = 0
    tmpcount = 0
    j = 0
    while j < N:
        if(i < j):
            tmpcount = N - j + i
        else:
            tmpcount = i - j
        tmpsum = a[j] + tmpcount * x
        if tmpsum < sumi:
            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:
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    l = [1]*len(a)
    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
            else:
                break
    for i in range(len(a)):
        if l[i] > 1:
            for j in range(1, l[i]):
                if l[(i+j)%len(a)] < 2:
                    l[(i+j)%len(a)] = 0
                else:
                    l[i] = j
                    break
    print(sum(a[x]*l[x] for x in range(len(a))) + (max(l)-1) * x)
if __name__ == '__main__':
    main()

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 catch_all():
    global N, x, line2, caught, time
    for i in xrange(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:
import numpy as np


tflag = False
if tflag:
#  st = time.time()
  N = 2000
  m = 1000000000
  x = np.random.randint(m)
  A = np.random.randint(m,size=(N))
else:
  a = map(int,raw_input().split())
  N = a[0]
  x = a[1]
  A = map(int,raw_input().split())

ma = min(A)

B = np.zeros(N)
E = np.zeros(N)
C = 10000000000*np.ones((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


tflag = False
if tflag:
#  st = time.time()
  N = 2000
  m = 1000000000
  x = np.random.randint(m)
  A = np.random.randint(m,size=(N))
else:
  a = map(int,raw_input().split())
  N = a[0]
  x = a[1]
  A = map(int,raw_input().split())

ma = min(A)

B = np.zeros(N)
E = np.zeros(N)
C = 10000000000*np.ones((N,N))
for idx in xrange(N):
  for i in xrange(N):
    if x*i > A[idx]:
      break
    C[idx][i] = A[idx-i]+x*i
    if x*(N-1) < A[idx] and A[idx-i] == ma:
      break
  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:
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
    all_get_time = sum(get_times)
    temp_change_num = max_change_num
    while True:
        temp_change_num += 1
        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 - temp_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)
        temp_all_get_time = sum(get_times)
        if all_get_time < temp_all_get_time + change_duration:
            break
        else:
            all_get_time = temp_all_get_time
            all_change_time += change_duration
    return all_get_time + all_change_time

print solve(num, change_duration, get_durations)

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 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 = map(int, raw_input().split())
a = map(int, raw_input().split())
b = a[:]
ma = 0
mi = min(a)
ind = a.index(mi)
for j in xrange(n):
    # print " j aj",j,a[j]
        if b[(ind+j-1)%n] + x < b[(ind+j)%n]:
            # print "  swap", i,a[j-i]
            ma += 1
                # print "   ma",ma
            b[(ind+j)%n] = b[(ind+j-1)%n]

print sum(b) + x * ma

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:
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    l = [1]*len(a)
    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]):
                if l[(i+j)%len(a)] < 2:
                    l[(i+j)%len(a)] = 0
                else:
                    l[i] = j
                    break
    print(sum(a[x]*l[x] for x in range(len(a))) + (max(l)-1) * x)
if __name__ == '__main__':
    main()

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
    all_get_time = sum(get_times)
    temp_change_num = max_change_num
    while True:
        temp_change_num += 1
        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 - temp_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)
        temp_all_get_time = sum(get_times)
        if all_get_time < temp_all_get_time + change_duration:
            break
    return all_get_time + all_change_time

print solve(num, change_duration, get_durations)

Submission status: Wrong Answer

Solution code:
import numpy as np


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

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)
C = 10000000000*np.ones((N,N))
for idx in xrange(N):
  for i in xrange(N):
    if x*i > A[idx]:
      break
    C[idx][i] = A[idx-i]+x*i
  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)