problem_id stringlengths 6 6 | user_id stringlengths 10 10 | time_limit float64 1k 8k | memory_limit float64 262k 1.05M | problem_description stringlengths 48 1.55k | codes stringlengths 35 98.9k | status stringlengths 28 1.7k | submission_ids stringlengths 28 1.41k | memories stringlengths 13 808 | cpu_times stringlengths 11 610 | code_sizes stringlengths 7 505 |
|---|---|---|---|---|---|---|---|---|---|---|
p03147 | u430726059 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nh=list(map(int, input().split()))\nans=0\nnum=0\nfor i in range(n):\n if num<h[i]:\n ans+=h[i]-num\n cnt=h[i]\nprint(ans)', 'n=int(input())\nh=list(map(int, input().split()))\nans=0\nnum=0\nfor i in range(n):\n if num<h[i]:\n ans+=h[i]-num\n num=h[i]\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s887738948', 's338939510'] | [9072.0, 9088.0] | [27.0, 28.0] | [134, 134] |
p03147 | u440129511 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["h=list(map(int,input().split()))\nl=[0]\nc='plus'\nfor i in range(n-1):\n if c=='minus' and h[i]<=h[i+1]:\n l.append(i)\n if h[i]<=h[i+1]:c='plus'\n else:c='minus'\n\nw=0\nm=0\nfor i in range(len(l)-1):\n w+=max(h[l[i]:l[i+1]+1])-m\n m=h[l[i+1]]\nw+=max(h[l[-1]:n])-m\nprint(w)", "n=int(input())\nh=list(map(int,input().split()))\nl=[0]\nc='plus'\nfor i in range(n-1):\n if c=='minus' and h[i]<=h[i+1]:\n l.append(i)\n if h[i]<=h[i+1]:c='plus'\n else:c='minus'\n\nw=0\nm=0\nfor i in range(len(l)-1):\n w+=max(h[l[i]:l[i+1]+1])-m\n m=h[l[i+1]]\nw+=max(h[l[-1]:n])-m\nprint(w)"] | ['Runtime Error', 'Accepted'] | ['s324589086', 's394052874'] | [3064.0, 3064.0] | [18.0, 17.0] | [284, 299] |
p03147 | u440975163 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\ns = list(int(input()))\ncost = s[0]\nfor i in range(1, n):\n if s[i - 1] < s[i]:\n cost += s[i] - s[i - 1]\nprint(cost)', 'n = int(input())\ns = list(map(int, input().split()))\ncost = s[0]\nfor i in range(1, n):\n if s[i - 1] < s[i]:\n cost += s[i] - s[i - 1]\nprint(cost)'] | ['Runtime Error', 'Accepted'] | ['s123412897', 's514977968'] | [2940.0, 2940.0] | [17.0, 17.0] | [141, 154] |
p03147 | u442030035 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nh = list(map(int, input().split()))\nf_h = [0 for i in range(N)]\njudge = [False if f_h[i] != h[i] else True for i in range(N)]\n\nct = 0\nwhile False in judge:\n flg = 0\n for i in range(N):\n if judge[i] is False:\n flg = 1\n f_h[i] += 1\n if f_h[i] == h[i]:\n judge[i] = True\n else:\n if flg == 1:\n ct += 1\n flg = 0\n else:\n pass\nprint(ct)\n', 'N = int(input())\nh = list(map(int, input().split()))\nf_h = [0 for i in range(N)]\njudge = [False if f_h[i] != h[i] else True for i in range(N)]\n\nct = 0\nwhile False in judge:\n flg = 0\n for i in range(N):\n if judge[i] is False:\n if i == N-1:\n f_h[i] += 1\n ct += 1\n if f_h[i] == h[i]:\n judge[i] = True\n else:\n flg = 1\n f_h[i] += 1\n if f_h[i] == h[i]:\n judge[i] = True\n else:\n if flg == 1:\n ct += 1\n flg = 0\n else:\n pass\nprint(ct)\n'] | ['Wrong Answer', 'Accepted'] | ['s795532309', 's771315582'] | [3064.0, 3064.0] | [20.0, 21.0] | [481, 663] |
p03147 | u454043187 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['count = 0\n# N = int(input())\nh = list(map(int, input().split()))\nhmin = min(h)\ncount =+ min(h)\nh = list(map(lambda x: x-hmin ,h))\nhmax = max(h)\nif hmax == 0:\n print(count)\nh.append(0)\nhamx = max(h)\nwhile hmax != 0:\n for i in range(len(h)):\n if h[i] <= 0:\n continue\n elif h[i-1] > 0:\n continue\n else:\n for j in range(i+1,len(h)+1):\n if h[j] > 0:\n continue\n else:\n count += 1\n break\n h = list(map(lambda x: x-1 ,h))\n hmax = max(h)\nprint(count)', 'import numpy as np\nimport sys\ncount = 0\nN = int(input())\nh = list(map(int, input().split()))\n\nh = map(lambda x: x-min(h) ,h)\ncount =+ min(h)\nif max(h) == 0:\n return count\n\nh = h.append(0)\nwhile max(h) !=0:\n for i in range(len(h)+1):\n if h[i] == 0:\n continue\n else:\n for j in range(i+1,len(h)+1):\n if h[j] != 0:\n continue\n else h[j] == 0:\n count += 1\n break\n h = map(lambda x: x-1 ,h)\nprint(count)', 'count = 0\nN = int(input())\nh = list(map(int, input().split()))\ncount =+ min(h)\nh = list(map(lambda x: x-min(h) ,h))\n# if max(h) == 0:\n# print(count)\nh.append(0)\nwhile max(h) != 0:\n for i in range(len(h)):\n if h[i] <= 0:\n continue\n elif h[i-1] > 0:\n continue\n else:\n for j in range(i+1,len(h)+1):\n if h[j] > 0:\n continue\n else:\n count += 1\n break\n h = list(map(lambda x: x-1 ,h))\nprint(count)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s032611470', 's745254388', 's794828476'] | [3064.0, 3064.0, 3064.0] | [17.0, 17.0, 23.0] | [596, 528, 544] |
p03147 | u463655976 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = input()\nH = map(int, input().split())\n\nHk = set()\nfor h in H:\n Hk.add(h)\n\ndef po(h, s, e):\n if h >= Hk[-1]:\n return 1\n posS = s\n hit = False\n cnt = 0\n for posE in range(s, e+1):\n if posE >= e or H[posE] <= Hk[h]:\n hit or= (posE < e)\n\tif posS < posE:\n cnt += po(h+1, posS, posE)\n if hit:\n cnt += 1\n return cnt\n\n', 'N = input()\nH = list(map(int, input().split()))\n\nHk = set([0])\nfor h in H:\n Hk.add(h)\nHk = sorted(Hk)\n\ndef po(h, s, e):\n posS = s\n cnt = 0\n for posE in range(s, e+1):\n if posE >= e or H[posE] <= Hk[h]:\n if posS < posE:\n cnt += po(h+1, posS, posE)\n posS = posE + 1\n if h > 0:\n cnt += Hk[h] - Hk[h-1]\n return cnt\n\nprint(po(0, 0, len(H)))\n'] | ['Runtime Error', 'Accepted'] | ['s430411486', 's200530638'] | [2940.0, 3064.0] | [17.0, 19.0] | [341, 365] |
p03147 | u474423089 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["N=int(input())\nH=list(map(int,input().split(' ')))\nans = 0\nfor i in range(N-1):\n ans += max(0,H[i+1]-H[i])\nprint(ans)", "N=int(input())\nH=list(map(int,input().split(' ')))\nans = H[0]\nfor i in range(N-1):\n ans += max(0,H[i+1]-H[i])\nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s133592944', 's921642590'] | [2940.0, 2940.0] | [17.0, 17.0] | [120, 123] |
p03147 | u474925961 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\nn=int(input())\nh=list(map(int,input().split()))\nh.insert(0,0)\nh.append(0)\np=max(h)\narr=np.array(h)\ncnt=0\nfor i in range(p,1,-1):\n x=np.copy(arr)\n x[x!=i]=0\n x[x==i]=1\n temp=np.arange(len(x))\n temp[x>0]=0\n np.maximum.accumulate(temp,out=temp)\n left=temp\n x_reversed=x[::-1]\n temp=np.arange(len(x))\n temp[x_reversed>0]=0\n np.maximum.accumulate(temp,out=temp)\n right=len(x)-1-temp[::-1]\n y=right-left-1\n y[x==0]=0 \n z=np.nonzero(np.diff(np.nonzero(x==0)[0])-1)\n cnt+=len(z[0])\n arr=arr-x\nprint(cnt)\n\n \n ', 'import numpy as np\nn=int(input())\nh=list(map(int,input().split()))\nh.insert(0,0)\nh.append(0)\np=max(h)\narr=np.array(h)\ncnt=0\nfor i in range(p,0,-1):\n x=np.copy(arr)\n x[x!=i]=0\n x[x==i]=1\n temp=np.arange(len(x))\n temp[x>0]=0\n np.maximum.accumulate(temp,out=temp)\n left=temp\n x_reversed=x[::-1]\n temp=np.arange(len(x))\n temp[x_reversed>0]=0\n np.maximum.accumulate(temp,out=temp)\n right=len(x)-1-temp[::-1]\n y=right-left-1\n y[x==0]=0 \n z=np.nonzero(np.diff(np.nonzero(x==0)[0])-1)\n cnt+=len(z[0])\n arr=arr-x\nprint(cnt)\n\n \n '] | ['Wrong Answer', 'Accepted'] | ['s758520447', 's328851177'] | [14440.0, 12524.0] | [159.0, 157.0] | [577, 577] |
p03147 | u476124554 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nh = list(map(int,input().split()))\ndef f(arr):\n print(arr)\n if(sum(arr) == 0):\n return 0\n while(arr[0] == 0):\n arr.pop(0)\n while(arr[-1] == 0):\n arr.pop()\n if (min(arr) == 0):\n index = arr.index(0)\n return f(arr[0:index]) + f(arr[index: len(arr)])\n else:\n minval = min(arr)\n if (len(arr) == 1):\n return minval\n else:\n arr = list(map(lambda x: x- minval, arr))\n if(sum(arr)==0):\n return minval\n else:\n return f(arr) + minval\nprint(f(h)) ', 'N = int(input())\nh = list(map(int,input().split()))\ndef f(arr):\n if(sum(arr) == 0):\n return 0\n while(arr[0] == 0):\n arr.pop(0)\n while(arr[-1] == 0):\n arr.pop()\n if (min(arr) == 0):\n index = arr.index(0)\n return f(arr[0:index]) + f(arr[index: len(arr)])\n else:\n minval = min(arr)\n if (len(arr) == 1):\n return minval\n else:\n arr = list(map(lambda x: x- minval, arr))\n if(sum(arr)==0):\n return minval\n else:\n return f(arr) + minval\nprint(f(h)) '] | ['Wrong Answer', 'Accepted'] | ['s894045717', 's712139336'] | [3064.0, 3064.0] | [19.0, 19.0] | [601, 586] |
p03147 | u494379309 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['def all_water(h_list):\n if len(h_list) == 0:\n return 0\n min_h = min(h_list)\n new_list = [x - min_h for x in h_list]\n i = new_list.index(0)\n return min_h + all_water(new_list[:i]) + all_water(new_list[i+1:])\n\nn = input()\n\nheight = list(map(int,input().split(" ")))\n\nprint(allwater(height))', 'def all_water(h_list):\n if len(h_list) == 0:\n return 0\n min_h = min(h_list)\n h_list = list(map(lambda x:x-minh, h_list))\n i = h_list.index(0)\n return min_h + all_water(h_list[:i]) + all_water(h_list[i+1:])\n\nn = input()\n\nheight = list(map(int,input().split(" ")))\n\nprint(allwater(height))', 'def all_water(h_list):\n if len(h_list) == 0:\n return 0\n min_h = min(h_list)\n new_list = list(map(lambda x:x-minh, h_list))\n i = new_list.index(0)\n return min_h + all_water(new_list[:i]) + all_water(new_list[i+1:])\n\nn = input()\n\nheight = list(map(int,input().split(" ")))\n\nprint(allwater(height))', 'def all_water(h_list):\n if len(h_list) == 0:\n return 0\n min_h = min(h_list)\n new_list = [x - min_h for x in h_list]\n i = new_list.index(0)\n return min_h + all_water(new_list[:i]) + all_water(new_list[i+1:])\n\nn = input()\n\nheight = list(map(int,input().split(" ")))\n\nprint(all_water(height))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s151728389', 's331689781', 's367390276', 's244819957'] | [3060.0, 3060.0, 3060.0, 3060.0] | [17.0, 17.0, 17.0, 18.0] | [296, 295, 303, 297] |
p03147 | u496744988 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["n = int(input())\nh = list(map(int, input().split()))\n\n\ndef mizuyari(partial_list):\n count = 0\n print(partial_list)\n if len(partial_list) == 0:\n print('end return------------ 0 ')\n return 0\n if len(partial_list) == 1:\n print('end return------' + str(partial_list[0]))\n return partial_list[0]\n \n if min(partial_list) != 0:\n count += min(partial_list)\n print('count --------' + str(min(partial_list)))\n partial_list = list(map(lambda x: x-min(partial_list), partial_list))\n zero_index = []\n \n for i in range(len(partial_list)):\n if partial_list[i] == 0:\n zero_index.append(i)\n print(zero_index)\n bunkatsu = []\n bunkatsu.append(partial_list[0:zero_index[0]])\n for i in range(0, len(zero_index)-1):\n bunkatsu.append(partial_list[zero_index[i]+1:zero_index[i+1]])\n bunkatsu.append(partial_list[zero_index[(len(zero_index)-1)]+1:len(partial_list)])\n print(bunkatsu)\n for i in bunkatsu:\n count += mizuyari(i)\n return count\n\n\nprint(mizuyari(h))\n", "n = int(input())\nh = list(map(int, input().split()))\n\n\ndef mizuyari(partial_list):\n count = 0\n # print(partial_list)\n if len(partial_list) == 0:\n # print('end return------------ 0 ')\n return 0\n if len(partial_list) == 1:\n # print('end return------' + str(partial_list[0]))\n return partial_list[0]\n \n if min(partial_list) != 0:\n count += min(partial_list)\n # print('count --------' + str(min(partial_list)))\n partial_list = list(map(lambda x: x-min(partial_list), partial_list))\n zero_index = []\n \n for i in range(len(partial_list)):\n if partial_list[i] == 0:\n zero_index.append(i)\n \n bunkatsu = []\n bunkatsu.append(partial_list[0:zero_index[0]])\n for i in range(0, len(zero_index)-1):\n bunkatsu.append(partial_list[zero_index[i]+1:zero_index[i+1]])\n bunkatsu.append(partial_list[zero_index[(len(zero_index)-1)]+1:len(partial_list)])\n \n for i in bunkatsu:\n count += mizuyari(i)\n return count\n\n\nprint(mizuyari(h))\n"] | ['Wrong Answer', 'Accepted'] | ['s234724453', 's644307093'] | [3316.0, 3188.0] | [27.0, 26.0] | [1182, 1194] |
p03147 | u497046426 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nH = list(map(int, input().split()))\n\n\n\n\nans = 0\nwhile sum(H) > 0:\n left = right = 0\n prev = -1\n segment = []\n for i, h in enumerate(H):\n if h == 0 and prev != 0:\n right = i\n if left != right:\n segment.append((left, right))\n left = i\n elif h != 0 and prev == 0:\n left = i\n prev = h\n right = i + 1\n segment.append((left, right))\n ans += len(segment)\n \n for l, r in segment:\n for i in range(l, r):\n H[i] -= 1\nprint(ans)', 'N = int(input())\nH = list(map(int, input().split()))\n\nstack = [H]\ncount = 0\nwhile stack:\n lst = stack.pop()\n m = min(lst)\n count += m\n lst = [l-m for l in lst]\n prev = 0\n left = 0\n for i, h in enumerate(lst):\n if h == 0 and prev != 0: \n stack.append(lst[left:i])\n elif h != 0 and prev == 0:\n left = i\n if i == len(lst)-1: \n stack.append(lst[left:i+1])\n elif h != 0 and i == len(lst)-1: \n stack.append(lst[left:i+1])\n prev = h\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s589342433', 's346529151'] | [3064.0, 3064.0] | [23.0, 20.0] | [723, 699] |
p03147 | u499966353 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nheights = list(map(int, input().split()))\n\ndef nextgen(comb):\n lis = comb[0]\n j = comb[1]\n for i in range(len(lis)-1):\n if (i != len(lis) and (lis[i] == 0 and lis[i+1] != 0)) or (i == 0 and lis[i] != 0):\n j += 1\n if lis[i] != 0:\n lis[i] -= 1\n if lis[len(lis)-1] != 0:\n lis[len(lis)-1] -= 1\n return [lis, j]\n\ncomb = [heights, 0]\nwhile (comb[0].count(0) != len(comb[0])):\n comb = test(comb)\n\nprint(comb[1])', 'n = int(input())\nheights = list(map(int, input().split()))\n\ndef nextgen(comb):\n lis = comb[0]\n j = comb[1]\n if len(lis) == 1 and lis[0] != 0:\n j += 1 \n for i in range(len(lis)-1):\n if (i != len(lis) and (lis[i] == 0 and lis[i+1] != 0)) or (i == 0 and lis[i] != 0):\n j += 1\n if lis[i] != 0:\n lis[i] -= 1\n if lis[len(lis)-1] != 0:\n lis[len(lis)-1] -= 1\n return [lis, j]\n\ncomb = [heights, 0]\nwhile (comb[0].count(0) != len(comb[0])):\n comb = nextgen(comb)\n\nprint(comb[1])'] | ['Runtime Error', 'Accepted'] | ['s422546790', 's543848712'] | [3064.0, 3064.0] | [18.0, 20.0] | [482, 540] |
p03147 | u506858457 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N=int(input())\nL=[int(i) for i in range(N)]\nL.append(0)\nans=0\nfor i in range(N):\n ans+=max(0,L[i]-L[i+1])\nprint(ans)', 'N=int(input())\nL=[int(i) for i in input().split()]\n#L.append(0)\nL.insert(0,0)\nans=0\nfor i in range(N):\n ans+=max(0,L[i+1]-L[i])\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s084300224', 's570230901'] | [3316.0, 2940.0] | [20.0, 17.0] | [117, 140] |
p03147 | u509911932 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import bisect\n\n\ndef mizuyari(flowers):\n if flowers == []:\n return 0\n # print(flowers)\n minheight = min(flowers)\n if minheight == 0:\n if max(flowers) == 0:\n return 0\n leftindex = flowers.index(0)\n \n count = mizuyari(flowers[0:leftindex])+mizuyari(flowers[leftindex:])\n return count\n else:\n count = mizuyari([i - minheight for i in flowers]) + minheight\n return count\n\n\nN = int(input())\nh_list = list(map(int, input().split()))\n\nprint(mizuyari(h_list))\n', 'import bisect\n\n\ndef mizuyari(flowers):\n if flowers == []:\n return 0\n # print(flowers)\n minheight = min(flowers)\n if minheight == 0:\n if max(flowers) == 0:\n return 0\n leftindex = flowers.index(0)\n \n if leftindex == len(flowers):\n count = mizuyari(flowers[0:leftindex])\n else:\n count = mizuyari(flowers[0:leftindex]) + \\\n mizuyari(flowers[leftindex+1:])\n\n return count\n else:\n count = mizuyari([i - minheight for i in flowers]) + minheight\n return count\n\n\nN = int(input())\nh_list = list(map(int, input().split()))\n\nprint(mizuyari(h_list))\n\n'] | ['Runtime Error', 'Accepted'] | ['s946960932', 's728264302'] | [4988.0, 3188.0] | [85.0, 18.0] | [585, 698] |
p03147 | u518042385 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\nn=int(input())\nl=np.array(list(map(int,input().split())))\nc=0\nfor i in range(n):\n for j in range(i,n):\n if 0 in l[i:j+1]:\n pass\n else:\n l[i:j+1]=l[i:j+1]-np.array([min(l[i:j+1])]*(j-i+1))\n c+=min(l[i:j+1])\nprint(c)\n', 'n=int(input())\nl=list(map(int,input().split()))\nc=0\nfor i in range(n):\n for j in range(i,n):\n if 0 in l[i:j+1]:\n pass\n else:\n l[i:j+1]-=1\n c+=1\nprint(c)', 'import numpy as np\nn=int(input())\nl=np.array(list(map(int,input().split())))\nc=0\nfor i in range(n):\n for j in range(i,n):\n if 0 in l[i:j+1]:\n pass\n else:\n l[i:j+1]=l[i:j+1]-np.array([1]*(j-i+1))\n c+=1\nprint(c)', 'import numpy as np\nn=int(input())\nl=np.array(list(map(int,input().split())))\nc=0\nfor i in range(n):\n for j in range(n-i):\n if 0 in l[i:n-j]:\n pass\n else:\n c+=min(l[i:n-j])\n l[i:n-j]=l[i:n-j]-np.array([min(l[i:n-j])]*(n-j-i))\nprint(c)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s307810094', 's309359307', 's441131015', 's651079172'] | [12396.0, 2940.0, 12396.0, 12396.0] | [174.0, 20.0, 180.0, 176.0] | [256, 174, 231, 255] |
p03147 | u518064858 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nh=list(map(int,input().split()))\nans=0\nwhile any(h)==True:\n flag=0\n for i in range(n):\n if h[i]>0:\n h[i]-=1\n flag=1\n else:\n if flag==1:\n ans+=1\n flag=0\n if i==n-2:\n if h[n-1]>0:\n h[n-1]-=1\n ans+=1\n break\n else:\n if h[i]>0:\n ans+=1\n break\nprint(ans)\n', 'n=int(input())\nh=list(map(int,input().split()))\nans=0\nif n==1:\n print(h[0])\n exit()\nwhile any(h)==True:\n flag=0\n for i in range(n-1):\n if h[i]>0:\n h[i]-=1\n flag=1\n else:\n if flag==1:\n ans+=1\n flag=0\n if i==n-2:\n if h[n-1]>0:\n h[n-1]-=1\n ans+=1\n else:\n if flag==1:\n ans+=1\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s598782996', 's964825177'] | [3188.0, 3064.0] | [21.0, 20.0] | [470, 465] |
p03147 | u518987899 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["N = int(input().strip())\nH = list(map(int, input().strip().split(' ')))+[0]\ncount = 0\nfor _ in range(max(H)-1):\n l = 0\n for r in range(1,len(H)):\n if H[r] < H[l]:\n \n H[l:r] = [h-1 for h in H[l:r]]\n count += 1\n l = r\n elif H[r] > H[l]:\n しない\n l = r\n else:\n continue\nprint(count+1)", "N = int(input().strip())\nH = list(map(int, input().strip().split(' ')))+[0]\ncount = 0\nfor _ in range(max(H)):\n l = 0\n m = max(H)\n for r in range(1,len(H)):\n if H[r] != m:\n if H[l] == m:\n \n H[l:r] = [h-1 for h in H[l:r]]\n count += 1\n l = r\n else:\n if H[l] != m:\n l = r\nprint(count)"] | ['Wrong Answer', 'Accepted'] | ['s189013237', 's093626185'] | [3064.0, 3064.0] | [23.0, 23.0] | [352, 343] |
p03147 | u525595811 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nhn = list(map(int, input().split()[:n]))\n\ni = 0\nres = []\nwhile True:\n for h in hn:\n if h > 0:\n res.append(h-1)\n else:\n res.append(h)\n hn = res\n res = []\n if sum(hn) == 0:\n print(i)\n break\n i += 1\n', 'n = int(input())\nhn = list(map(int, input().split()[:n]))\n\ncount = 0\nprev = 0\n\nfor h in hn:\n count += max(0, h-prev)\n prev = h\n\nprint(count)\n'] | ['Wrong Answer', 'Accepted'] | ['s137444576', 's510238030'] | [2940.0, 2940.0] | [19.0, 17.0] | [278, 147] |
p03147 | u527261492 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import sys\nn=int(input())\nh=list(map(int,input().split()))\nif len(set(h))==1:\n print(h[0])\n sys.exit()\nh.append(1-2)\ntotl=0\nfor i in range(1,max(h)+1):\n cnt=1\t\n for j in range(n):\n if h[j]<i:\n if i<=h[j+1]:\n cnt+=1\n totl+=cnt\nprint(totl)\n \n \n \n', 'import sys\nn=int(input())\nh=list(map(int,input().split()))\nif len(set(h))==1:\n print(h[0])\n sys.exit()\ntotl=0\nfor i in range(1,max(h)+1):\n cnt=0\n if i<=h[0]:\n cnt+=1\n for j in range(n-1):\n if h[j]<i:\n if i<=h[j+1]:\n cnt+=1\n totl+=cnt\nprint(totl)\n \n \n \n'] | ['Wrong Answer', 'Accepted'] | ['s789419333', 's169730512'] | [3064.0, 3064.0] | [19.0, 19.0] | [280, 292] |
p03147 | u529012223 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\nN = int(input())\nh = list(map(int, input().split()))\nh = np.array(h)\nh_diff = h[1:] - h[:N-1]\ncount = 0\nprint(h_diff)\nfor i in range(N-1):\n count -= min(h_diff[i], 0)\n \nprint(count + h[N-1])', 'import numpy as np\nN = int(input())\nh = list(map(int, input().split()))\nh = np.array(h)\nh_diff = h[1:] - h[:N-1]\ncount = 0\nfor i in range(N-1):\n count -= min(h_diff[i], 0)\n \nprint(count + h[N-1])'] | ['Wrong Answer', 'Accepted'] | ['s938841667', 's878609293'] | [12488.0, 17824.0] | [151.0, 255.0] | [215, 201] |
p03147 | u536034761 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['def down(H, n):\n x = min(H)\n n += x\n for i in range(len(H)):\n H[i] -= x\n return H, n\n\nN = int(input())\nH = list(map(int, input().split()))\nn = 0\nH, n = down(H, n)\nprint(H)\n\nwhile not all(h == 0 for h in H):\n L = []\n H0 =[]\n for h in H:\n if h != 0:\n L.append(h)\n else:\n if L:\n L, n = down(L, n)\n H0 += L\n H0.append(0)\n L = []\n if L:\n L, n = down(L, n)\n H0 += L\n H = H0\n print(H)\n\nprint(n)', 'def down(H, n):\n x = min(H)\n n += x\n for i in range(len(H)):\n H[i] -= x\n return H, n\n\nN = int(input())\nH = list(map(int, input().split()))\nn = 0\nH, n = down(H, n)\n\nwhile not all(h == 0 for h in H):\n L = []\n H0 =[]\n for h in H:\n if h != 0:\n L.append(h)\n else:\n if L:\n L, n = down(L, n)\n H0 += L\n H0.append(0)\n L = []\n if L:\n L, n = down(L, n)\n H0 += L\n H = H0\n print(H)\n\nprint(n)', 'def down(H, n):\n x = min(H)\n n += x\n for i in range(len(H)):\n H[i] -= x\n return H, n\n\nN = int(input())\nH = list(map(int, input().split()))\nn = 0\nH, n = down(H, n)\nprint(H)\n\nwhile not all(h == 0 for h in H):\n L = []\n H0 =[]\n for h in H:\n if h != 0:\n L.append(h)\n else:\n if L:\n L, n = down(L, n)\n H0 += L\n H0.append(0)\n L = []\n if L:\n L, n = down(L, n)\n H0 += L\n H = H0\n\nprint(n)', 'def down(H, n):\n x = min(H)\n n += x\n for i in range(len(H)):\n H[i] -= x\n return H, n\n\nN = int(input())\nH = list(map(int, input().split()))\nn = 0\nH, n = down(H, n)\n\nwhile not all(h == 0 for h in H):\n L = []\n H0 =[]\n for h in H:\n if h != 0:\n L.append(h)\n else:\n if L:\n L, n = down(L, n)\n H0 += L\n H0.append(0)\n L = []\n if L:\n L, n = down(L, n)\n H0 += L\n H = H0\n\nprint(n)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s313512992', 's480503818', 's726488842', 's727560315'] | [9172.0, 9068.0, 9136.0, 9180.0] | [30.0, 30.0, 29.0, 29.0] | [444, 435, 433, 424] |
p03147 | u540761833 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["N = int(input())\narray = input().split(' ')\nharray = []\nfor z in array:\n z = int(z)\n harray.append(z)\ncounter = 0\nwhile harray != [0]*N:\n if 0 not in harray:\n a = min(harray)\n for i in range(len(harray)):\n harray[i] -= a\n counter += a\n else:\n zeroarray = [j for j, x in enumerate(harray) if x == 0]\n if len(zeroarray) == 1:\n if zeroarray[0] == 0:\n a = min(harray[1:])\n for y in range(1,N):\n harray[y] -= a\n counter += a\n elif zeroarray[0] == N-1:\n a = min(harray[:N-1])\n for y in range(N-1):\n harray[y] -= a\n counter += a\n else:\n a = min(harray[:zeroarray[0]])\n for y in range(zeroarray[0]):\n harray[y] -= a\n counter += a\n a = min(harray[zeroarray[0]+1:])\n for y in range(zeroarray[0]+1,N):\n harray[y] -= a\n counter += a\n else:\n for k in range(len(zeroarray)-1):\n if zeroarray[0] != 0:\n a = min(harray[:zeroarray[0]])\n for y in range(zeroarray[0]):\n harray[y] -= a\n counter += a\n if zeroarray[k+1] - zeroarray[k] == 1:\n continue\n else:\n a = min(harray[zeroarray[k]+1:zeroarray[k+1]])\n for y in range(zeroarray[k]+1,zeroarray[k+1]+1):\n harray[y] -= a\n counter += a\n if zeroarray[-1] != N-1:\n a = min(harray[zeroarray[-1]+1:])\n for y in range(zeroarray[-1]+1,N):\n harray[y] -= a\n counter += a\n \n\nprint(counter)", 'N = int(input())\nh = list(map(int,input().split()))\ncount = 0\n\ndef devide(h):\n global count\n while 0 not in h:\n for i in range(len(h)):\n h[i] -= 1\n count += 1\n h2 = []\n h3 = []\n for i in h:\n if i == 0:\n h2.append(h3)\n h3 = []\n if i != 0:\n h3.append(i)\n h2.append(h3)\n\n for i in h2:\n if i == []:\n continue\n else:\n devide(i)\n \ndevide(h)\nprint(count)'] | ['Time Limit Exceeded', 'Accepted'] | ['s944839547', 's749804536'] | [3192.0, 3064.0] | [2104.0, 19.0] | [1899, 487] |
p03147 | u545411641 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nh = list(map(int, input().split()))\n\nprint(h)\n\nans = 0\n\nwhile True:\n given_water = False\n is_continuous = False\n for i in range(N):\n if h[i] > 0:\n if is_continuous is False:\n ans += 1\n is_continuous = True\n h[i] -= 1\n given_water = True\n else: # h[i] == 0\n is_continuous = False\n print(ans)\n print(h)\n if given_water is False:\n break\n \nprint(ans)', 'N = int(input())\nh = list(map(int, input().split()))\n\nans = 0\ngiven_water = False\nwhile True:\n is_continuous = False\n for i in range(N):\n if h[i] > 0:\n if is_continuous is False:\n ans += 1\n is_continuous = True\n h[i] -= 1\n given_water = True\n else: # h[i] == 0\n is_continuous = False\n if given_water is False:\n break\n \nprint(ans)', 'N = int(input())\nh = list(map(int, input().split()))\n\nans = 0\n\nwhile True:\n given_water = False\n is_continuous = False\n for i in range(N):\n if h[i] > 0:\n if is_continuous is False:\n ans += 1\n is_continuous = True\n h[i] -= 1\n given_water = True\n else: # h[i] == 0\n is_continuous = False\n if given_water is False:\n break\n \nprint(ans)'] | ['Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s626410758', 's931243385', 's867792818'] | [3064.0, 3060.0, 3060.0] | [20.0, 2104.0, 19.0] | [417, 380, 383] |
p03147 | u547167033 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nh=list(map(int,input().split()))\ndef dfs(l,r):\n if l==r:\n return h[l]\n if r<l:\n return 0\n res=10**18\n for i in range(l,r+1):\n res=min(res,h[i])\n for i in range(l,r+1):\n h[i]-=res\n for i in range(l,r):\n if h[i]==0:\n return dfs(l,i-1)+dfs(i+1,r)+res\n return 0\nprint(dfs(0,n-1))', 'n=int(input())\nh=list(map(int,input().split()))\ndef dfs(l,r):\n if l==r:\n return h[l]\n if r<l:\n return 0\n res=10**18\n for i in range(l,r+1):\n res=min(res,h[i])\n for i in range(l,r+1):\n h[i]-=res\n for i in range(l,r+1):\n if h[i]==0:\n return dfs(l,i-1)+dfs(i+1,r)+res\n return 0\nprint(dfs(0,n-1))'] | ['Wrong Answer', 'Accepted'] | ['s394341635', 's102353839'] | [3064.0, 3064.0] | [20.0, 18.0] | [317, 319] |
p03147 | u548303713 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['def block():\n block=0\n count=0\n while count<=(n-1):\n if h[count]>=1:\n block+=1\n count+=1\n while count<=(n-1):\n if h[count]>=1:\n count+=1\n else:\n count+=1\n break\n return block\n \nn=int(input())\nh=list(map(int,input().split()))\nans=0\nwhile sum(h)>0:\n bl=block()\n mini=min(h)\n ans+=mini*bl\n for i in range(n):\n h[i]-=mini\n \nprint(ans)', 'def block():\n block=0\n count=0\n mini=200\n while count<=(n-1):\n if h[count]>=1:\n block+=1\n if h[count]<mini:\n mini=h[count]\n count+=1\n while count<=(n-1):\n if h[count]>=1:\n if h[count]<mini:\n mini=h[count]\n count+=1\n else:\n count+=1\n break\n return block,mini\n \nn=int(input())\nh=list(map(int,input().split()))\nans=0\nwhile sum(h)>0:\n bl,m=block()\n ans+=m*bl\n for i in range(n):\n h[i]-=m\n \nprint(ans)', 'N = int(input())\nh = list(map(int,input().split()))\ncnt = 0\n \nwhile sum(h) > 0:\n min_h = max(h)\n i = h.index(min_h)\n #print(i)\n while i < len(h):\n if h[i] == min_h:\n h[i] -= 1\n i += 1\n else:\n break\n cnt += 1\n \nprint(cnt)'] | ['Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s792470462', 's928717578', 's650204067'] | [3064.0, 3064.0, 3060.0] | [2104.0, 2104.0, 36.0] | [506, 640, 282] |
p03147 | u551351897 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['#include <bits/stdc++.h>\nusing namespace std;\ntemplate<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }\ntemplate<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }\ntypedef long long unsigned int ll;\n\n#define EPS (1e-7)\n#define INF (1e9)\n#define PI (acos(-1))\nint dx[4] = {1, 0, -1, 0};\nint dy[4] = {0, 1, 0, -1}; // 移動方向\n\n\nint n;\nint h[101];\n\nvoid input(){\n cin >> n;\n for(int i=0;i<n;i++) cin >> h[i];\n}\n\nint main()\n{\n cin.tie(0);\n ios::sync_with_stdio(false);\n input();\n int cnt = 0;\n for(int l=0;l<n;l++){\n while(h[l] > 0){\n int r;\n for(r=l+1;r<n;r++){\n if (h[r] == 0) break; \n }\n for(int x=l;x<r;x++) h[x]--;\n cnt++;\n }\n }\n cout << cnt << endl;\n return 0;\n}', 'import sys\ninput = sys.stdin.readline\n\ndef lsearch(h): \n for i in range(len(h)):\n if h[i] != 0:\n return i\n return len(h)-1\n\ndef rsearch(h, l): \n for i in range(l, len(h)):\n if h[i] == 0:\n return i\n return len(h)\n\nn=int(input())\nh=list(map(int, input().split()))\ncnt=0\nwhile any(h):\n l=lsearch(h)\n r=rsearch(h, l)\n for i in range(l, r):\n h[i] -= 1\n cnt+=1\nprint(cnt)'] | ['Runtime Error', 'Accepted'] | ['s909230674', 's619369589'] | [2940.0, 3188.0] | [18.0, 38.0] | [851, 466] |
p03147 | u552357043 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int, input().split()))\ngap = [0]\nmt = []\nva = []\ni = 0\nwhile i+1 <= len(h)-1:\n if h[i+1]-h[i] != 0:\n gap.append(h[i+1]-h[i])\n i += 1\n else:\n h.pop(i+1)\nfor i in range(h): \n if gap[i] >= 0: \n if gap[i+1] < 0:\n mt.append(h[i])\n else:\n if gap[i+1] > 0:\n va.append(h[i])\nif gap[-1] > 0 :\n mt.append(h[-1])\nif mt == []:\n mt.append(h[0])\nans = 0\nfor x in mt:\n ans += x\nfor x in va:\n ans -= x\nprint(ans)', 'n = int(input())\nh = list(map(int, input().split()))\ngap = [0]*n\nmt = []\nva = []\nfor i in range(n-1):\n gap[i+1] = h[i+1]-h[i]\n if gap[i] > 0: \n if gap[i+1] < 0:\n mt.append(h[i])\n else:\n if gap[i+1] > 0:\n va.append(h[i])\nif gap[-1] > 0 :\n mt.append(h[-1])\nif mt == []:\n mt.append(h[0])\nans = 0\nfor x in mt:\n ans += x\nfor x in va:\n ans -= x\nprint(ans)', 'n = int(input())\nh = list(map(int, input().split()))\ngap = [0]\nmt = []\nva = []\ni = 0\nwhile i+1 <= len(h)-1:\n if h[i+1]-h[i] != 0:\n gap.append(h[i+1]-h[i])\n i += 1\n else:\n h.pop(i+1)\nfor i in range(h) \n if gap[i] >= 0: \n if gap[i+1] < 0:\n mt.append(h[i])\n else:\n if gap[i+1] > 0:\n va.append(h[i])\nif gap[-1] > 0 :\n mt.append(h[-1])\nif mt == []:\n mt.append(h[0])\nans = 0\nfor x in mt:\n ans += x\nfor x in va:\n ans -= x\nprint(ans)', 'n = int(input())\nh = list(map(int, input().split()))\ngap = [0]\nmt = []\nva = []\ni = 0\nwhile i+1 <= len(h)-1:\n if h[i+1]-h[i] != 0:\n gap.append(h[i+1]-h[i])\n i += 1\n else:\n h.pop(i+1)\nfor i in range(len(h)-1): \n if gap[i] >= 0: \n if gap[i+1] < 0:\n mt.append(h[i])\n else:\n if gap[i+1] > 0:\n va.append(h[i])\nif gap[-1] > 0 :\n mt.append(h[-1])\nif mt == []:\n mt.append(h[0])\nans = 0\nfor x in mt:\n ans += x\nfor x in va:\n ans -= x\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s130318131', 's329152074', 's709866956', 's373241383'] | [3064.0, 3064.0, 2940.0, 3064.0] | [17.0, 17.0, 17.0, 18.0] | [510, 406, 509, 517] |
p03147 | u556225812 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nlst = list(map(int, input().split()))\ncnt = 0\nfor i in range(N-1):\n if lst[i] < lst[i+1]:\n cnt += \nprint(cnt)\n\n\n\n\n#139 c\nN = int(input())\nH = list(map(int, input().split()))\nmax_lst = []\nmin_lst = []\nmax_h = H[0]\nmin_h = H[0]\ns = 0\nfor i in range(1, N):\n if H[i-1] <= H[i]:\n if H[0] not in max_lst and H[0] not in min_lst:\n min_lst.append(H[0])\n if max_h == 0:\n min_lst.append(min_h)\n if i == N-1:\n max_lst.append(H[i])\n max_h = H[i]\n min_h = 0\n elif H[i-1] >= H[i]:\n if H[0] not in max_lst and H[0] not in min_lst:\n max_lst.append(H[0])\n s = 1\n if min_h == 0:\n max_lst.append(max_h)\n if i == N-1:\n min_lst.append(H[i])\n min_h = H[i]\n max_h = 0\ncnt = 0\nif s == 0:\n for i in range(len(min_lst)-1):\n cnt += max_lst[i] - min(min_lst[i], min_lst[i+1])\n cnt += max_lst[-1] - min_lst[-1]\nelse:\n for i in range(1, len(max_lst)):\n cnt += max_lst[i] - min(min_lst[i-1], min_lst[i])\n cnt += max_lst[0] - min_lst[0]\nprint(cnt)', 'N = int(input())\nH = list(map(int, input().split()))\nans = 0\nH.append(0)\nfor i in range(max(H)):\n cnt = 0\n for k in range(N):\n if H[k] != 0 and H[k+1] == 0:\n cnt += 1\n ans += cnt\n H = list(map(lambda x:(x-1, 0)[x == 0], H))\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s500796932', 's553553278'] | [2940.0, 3064.0] | [17.0, 20.0] | [1121, 264] |
p03147 | u557494880 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input().split())\nH = list(map(int,input().split()))\ny = 0\nz = H[i]\nans = 0\nfor i in range(N):\n x = H[i]\n if x >= y:\n y = x\n else:\n ans += y\n z = min(z,x)\n for j in range(i,N):\n p = H[j]\n z = min(z,p)\n H[j] -= z\nprint(ans)\n ', 'N = int(input())\nH = list(map(int,input().split()))\ny = 0\nz = H[0]\nans = 0\nwhile len(H) != 0:\n z = H[0]\n f = 1\n while z == 0:\n H.pop(0)\n if len(H) != 0:\n z = H[0]\n else:\n break\n for i in range(len(H)):\n x = H[i]\n if x == 0:\n ans += z\n for j in range(i):\n H[j] -= z\n z = H[0]\n f = 0\n break\n z = min(x,z)\n if f == 1:\n ans += z\n for i in range(len(H)):\n H[i] -= z\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s073894911', 's689176328'] | [3064.0, 3064.0] | [17.0, 20.0] | [308, 545] |
p03147 | u560867850 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['from fractions import gcd\nfrom functools import reduce\n\nN = int(input())\n\nH = list(map(lambda x: int(x) + 1, input().split()))\n\ndef it(items, count):\n if not items:\n return 0\n if len(items) == 1:\n return items[0] + count\n\n ids = [-1]\n for i in range(len(items)):\n items[i] -= 1\n if items[i] <= 0:\n ids.append(i)\n ids.append(len(items))\n\n ans = 0\n for i in range(len(ids)-1):\n next_items = items[ids[i]+1:ids[i+1]]\n ans += it(next_items, count+1)\n if next_items:\n count = -1\n\n return ans\n\nprint(it(H, -1))\n', 'import sys\nsys.setrecursionlimit(10**8)\nN = int(input())\n\nH = list(map(lambda x: int(x) + 1, input().split()))\n\ndef it(items, count):\n if not items:\n return 0\n if len(items) == 1:\n return items[0] + count\n\n ids = [-1]\n for i in range(len(items)):\n items[i] -= 1\n if items[i] <= 0:\n ids.append(i)\n ids.append(len(items))\n\n ans = 0\n for i in range(len(ids)-1):\n next_items = items[ids[i]+1:ids[i+1]]\n ans += it(next_items, count+1)\n if next_items:\n count = -1\n\n return ans\n\nprint(it(H, -1))\n', 'n = int(input())\nh = list(map(int, input().split()))\nans = 0\npre = 0\nfor i in h:\n ans += max(0, i-pre)\n pre = i\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s533303189', 's801565770', 's929053274'] | [5176.0, 3064.0, 2940.0] | [40.0, 22.0, 17.0] | [600, 584, 129] |
p03147 | u572343785 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['h_state=[0]*n\n\ndef water(n,h,h_state):\n for i in range(n):\n if h_state[i]<h[i]:\n l=i\n break\n elif i==n-1 and h_state[i]<h[i]:\n l=i\n else:\n l=i+1\n \n for j in range(l,n):\n if h_state[j]==h[j]:\n r=j-1\n break\n else:\n r=j\n \n for k in range(l,r+1):\n h_state[k]+=1\n\ncnt=0\nwhile h_state != h:\n for i in range(n):\n if h_state[i]<h[i]:\n cnt+=1\n water(n,h,h_state)\n break\nprint(cnt)\n ', 'n=int(input())\nh=[int(x) for x in input().split()]\n\nh_state=[0]*n\n\ndef water(n,h,h_state):\n for i in range(n):\n if h_state[i]<h[i]:\n l=i\n break\n elif i==n-1 and h_state[i]<h[i]:\n l=i\n else:\n l=i+1\n \n for j in range(l,n):\n if h_state[j]==h[j]:\n r=j-1\n break\n else:\n r=j\n \n for k in range(l,r+1):\n h_state[k]+=1\n\ncnt=0\nwhile h_state != h:\n for i in range(n):\n if h_state[i]<h[i]:\n cnt+=1\n water(n,h,h_state)\n break\nprint(cnt)\n '] | ['Runtime Error', 'Accepted'] | ['s175922160', 's620751184'] | [9104.0, 9220.0] | [25.0, 79.0] | [557, 609] |
p03147 | u583507988 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["n=int(input())\nh=[0]+list(map(int,input().split()))+[0]\nma=0\nmi=float('inf')\nans=0\nfor i in range(n+1):\n if h[i]<=h[i+1]:\n ma=max(ma,h[i+1],h[i])\n mi=min(mi,h[i])\n else:\n ans+=ma-mi\n ma=0\n mi=float('inf')\nprint(ans)", "n=int(input())\nh=[0]+list(map(int,input().split()))+[0]\nma=0\nmi=float('inf')\nans=0\nfor i in range(n+1):\n if h[i]<=h[i+1]:\n ma=max(ma,h[i+1])\n mi=min(mi,h[i])\n else:\n ans+=ma-mi\n ma=0\n mi=float('inf')\nprint(ans)", "n=int(input())\nh=[0]+list(map(int,input().split()))+[0]\nma=0\nmi=float('inf')\nans=0\nfor i in range(n+1):\n if h[i]<=h[i+1]:\n ma=max(ma,h[i+1])\n mi=min(mi,h[i])\n else:\n ans+=ma-mi\n ma=h[i+1]\n mi=h[i+1]\nprint(ans)"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s168255243', 's609208843', 's092365097'] | [9152.0, 9204.0, 9108.0] | [29.0, 30.0, 31.0] | [232, 227, 226] |
p03147 | u604341914 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nH = list(map(int, input().split()))\nH = [h - min(H) for h in H]\n\nans = 0\nfor i in range(N-1):\n diff = H[i+1] - H[i]\n if i != N-2:\n if diff < 0:\n ans += abs(diff)\n else:\n if diff < 0:\n ans += abs(diff)\n else:\n ans += H[-1]\n\nprint(ans + min(H))', 'N = int(input())\nH = list(map(int, input().split()))\n\nans = H[0]\nfor i in range(N-1):\n dif = H[i+1] - H[i]\n if dif > 0:\n ans += dif\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s027865266', 's674699632'] | [3064.0, 2940.0] | [17.0, 18.0] | [322, 156] |
p03147 | u606033239 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nh=list(map(int,input().split()))\na=0\nfor i in range(1,max(h)+1):\n s=0\n while s<n:\n if h[s]>=i:\n a+=1\n while s<n and h[s]>=i:\n s+=1\n s+=1\nprint(a)', 'n=int(input())\nh=list(map(int,input().split()))\na=0\nfor i in range(1,max(h)+1):\n s=0\n while s<n:\n if h[s]>=i:\n a+=1\n s+=1\nprint(a)', 'n=int(input())\nh=list(map(int,input().split()))\na=0\nfor i in range(1,max(h)+1):\n s=0\n while s<n:\n if h[s]>=i:\n a+=1\n while s<n and h[s]>=i:\n s+=1 \n s+=1\nprint(a)'] | ['Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s024790793', 's028902732', 's858666344'] | [3060.0, 2940.0, 3060.0] | [2104.0, 20.0, 21.0] | [213, 161, 218] |
p03147 | u608053762 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh_list = [int(i) for i in input().split()]\n\nk = 0\nwhile sum(h_list)>0:\n bool_list = [True if i==max(h_list) else False for i in h_list]\n indexes = []\n true_index = bool_list.index(True)\n indexes.append(true_index)\n while bool_list(true_index):\n true_index += 1\n indexes.append(true_index)\n h_list = [h_list[i]-1 for i in indexes]\n k += 1\n \nprint(k)\n ', 'n = int(input())\nh_list = [int(i) for i in input().split()]\n\nk = 0\nwhile any([i > 0 for i in h_list]):\n bool_list = [True if i==max(h_list) else False for i in h_list]\n indexes = []\n true_index = bool_list.index(True)\n while bool_list[true_index]:\n indexes.append(true_index)\n true_index += 1\n if true_index == len(h_list):\n break\n\n h_list = [h_list[i]-1 if i in indexes else h_list[i] for i in range(len(h_list))]\n k += 1\n \nprint(k)'] | ['Runtime Error', 'Accepted'] | ['s412974261', 's356500248'] | [3060.0, 3064.0] | [18.0, 960.0] | [384, 484] |
p03147 | u609061751 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import sys\ninput = sys.stdin.readline\nimport numpy as np\nN = int(input())\nh = [int(x) for x in input().split()] + [0]\nh = np.array(h,np.int64)\nans = 0\nfor i in range(N):\n if h[i] > 0:\n j = i + 1\n while h[j] > h[i]:\n h[j] -= h[i]\n j += 1\n nexth = h[j]\n ans += h[j]\n for k in range(i,j+1):\n h[k] -= h[j]\n ans += h[i]\n h[i] = 0\nprint(ans)', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nN = int(input())\nh = [int(x) for x in input().split()] + [0]\nh = np.array(h,np.int64)\nans = 0\nfor i in range(N):\n if h[i] > 0:\n j = i + 1\n while h[j] > h[i]:\n h[j] -= h[i]\n j += 1\n nexth = h[j]\n h[i] -= h[j]\n ans += h[i]\n h[i] = 0\nprint(ans)', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\nN = int(input())\nh = [int(x) for x in input().split()]\nh = np.array(h,np.int64)\nans = 0\ndef split_(A):\n global ans\n if np.count_nonzero(A != 0) == 0:\n return\n else:\n minA = A.min()\n A -= minA\n ans += minA\n for i in range(len(A)):\n if A[i] == 0:\n split_(A[:i])\n split_(A[i+1:])\n break\nsplit_(h)\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s087036997', 's376401189', 's426727176'] | [12444.0, 12448.0, 12404.0] | [155.0, 152.0, 153.0] | [420, 365, 461] |
p03147 | u610473220 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nhList = list(map(int, input().split()))\n\nans = 0\ncou = 0\n\nhList = [0] + hList\n\nfor i in range(N):\n if hList[i] < hList[i+1]:\n cou = hList[i+1] - hList[i]\n else:\n ans += cou\n cou = 0\nans += cou\nprint(ans)', 'N = int(input())\nhList = list(map(int, input().split()))\n\nans = 0\ncou = 0\n\nhList = [0] + hList\n\nfor i in range(N):\n if hList[i] < hList[i+1]:\n cou += (hList[i+1] - hList[i])\n else:\n ans += cou\n cou = 0\nans += cou\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s355513854', 's887585712'] | [3064.0, 3064.0] | [18.0, 17.0] | [247, 250] |
p03147 | u621509924 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N=int(input())\nh=list(map(int,input().split()))\np=h[0]\nfor i in range(N-1):\n if h[i]<h[i+1]:\n p=h[i+1]\n else:\n p=p\n\nq=1\nr=0\nif p==0:\n print(0)\nelse:\n while q<=p:\n if h[0]>=q:\n r=r+1\n else:\n r=r\n for i in range(N-1):\n if h[i]<q and h[i+1]>=q:\n r=r+1\n else:\n r=r\n q=q+1\n\nprint(r)', 'N=int(input())\nh=list(map(int,input().split()))\np=h[0]\nfor i in range(N-1):\n if p<h[i+1]:\n p=h[i+1]\n else:\n p=p\n \nq=1\nr=0\nif p==0:\n print(0)\nelse:\n while q<=p:\n if h[0]>=q:\n r=r+1\n else:\n r=r\n for i in range(N-1):\n if h[i]<q and h[i+1]>=q:\n r=r+1\n else:\n r=r\n q=q+1\n print(r)'] | ['Runtime Error', 'Accepted'] | ['s794731968', 's549672234'] | [3064.0, 3064.0] | [17.0, 19.0] | [392, 398] |
p03147 | u623687794 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nflowers=[0]+list(map(int,input().split()))\nans=0\nfor i in range(1,n+1):\n ans+=max(flowers[i+1]-flowers[i],0)\nprint(ans)', 'n=int(input())\nflowers=[0]+list(map(int,input().split()))\nans=0\nfor i in range(n):\n ans+=max(flowers[i+1]-flowers[i],0)\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s386744538', 's921053864'] | [2940.0, 2940.0] | [17.0, 18.0] | [135, 132] |
p03147 | u623819879 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["n=int(input())\nh=list(map(int,input()))\nhm=max(h)\ns=['']*hm\nfor k in range(hm+1):\n for i in range(n):\n if h[i]>=k:\n s[k]+='#'\n else:\n s[k]+=' '\n\nans=0\nfor k in range(hm+1):\n ans+=len(list(s[k].split()))\nprint(ans)", "n=int(input())\nh=list(map(int,input().split()))\nhm=max(h)\ns=['']*hm\nfor k in range(1,hm+1):\n for i in range(n):\n if h[i]>=k:\n s[k-1]+='#'\n else:\n s[k-1]+=' '\n\n#print(s)\nans=0\nfor k in range(hm):\n ans+=len(list(s[k].split()))\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s309589537', 's384371239'] | [3064.0, 3060.0] | [18.0, 20.0] | [231, 254] |
p03147 | u627886394 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["N = int(input())\nh_list = list(map(int, input().split(' ')))\n\n\ndef mizuyari(h_list, l, r):\n import pdb;pdb.set_trace()\n num_mizuyari = min(h_list[l:r+1])\n h_list = [h - num_mizuyari if l <= x and x <= r else h for x, h in enumerate(h_list)]\n zero_posi = h_list[l:].index(0) + l\n if l == zero_posi:\n first_non_zero_posi = [x for x, h in enumerate(h_list) if h != 0]\n if not first_non_zero_posi:\n print(sum_mizuyari + num_mizuyari)\n exit()\n l = first_non_zero_posi[0]\n if list(range(l, len(h_list))) == first_non_zero_posi:\n return h_list, num_mizuyari, l, len(h_list)\n zero_posi = h_list[l:].index(0) + l\n new_r = zero_posi - 1\n return h_list, num_mizuyari, l, new_r\nl = 0\nr = len(h_list) - 1\nsum_mizuyari = 0\nwhile True:\n h_list, num_mizuyari, l, r = mizuyari(h_list, l, r)\n sum_mizuyari += num_mizuyari", "N = int(input())\nh_list = list(map(int, input().split(' ')))\n\ndef grouping(h_list):\n groups = []\n group = []\n for h in h_list:\n if h == 0:\n if group != []:\n groups.append(group)\n group = []\n continue\n group.append(h)\n if group:\n groups.append(group)\n return groups\n\n\nsum_mizuyari = []\ndef groups_mizuyari(h_list):\n num_mizuyari = min(h_list)\n h_list = [h - num_mizuyari for h in h_list]\n sum_mizuyari.append(num_mizuyari)\n groups = grouping(h_list)\n for group in groups:\n groups_mizuyari(group)\n\ngroups_mizuyari(h_list)\nprint(sum(sum_mizuyari))"] | ['Runtime Error', 'Accepted'] | ['s519321773', 's401581373'] | [6116.0, 3188.0] | [68.0, 19.0] | [898, 651] |
p03147 | u628707847 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int,input().split()))\nans = 0\n\nwhile min(h) != 0:\n h = list(map(lambda x: x-1,h))\n ans += 1\n\nwhile sum(h) != 0:\n flag = False\n for i in range(n):\n if i == n-1:\n h[i] -= 1\n ans += 1\n break\n if h[i] == 0 and flag:\n ans += 1\n break\n elif h[i] != 0:\n h[i] -= 1\n flag = True\nelse:\n print(ans)', 'def calc(list1,list2):\n for l in list2:\n list1[l] += 1\n return list1\n\nn = int(input())\nh = list(map(int,input().split()))\nf = [0]*n\nans = 0\n\nfor i in range(min(h)):\n f = [x+1 for x in f]\n ans += 1\n\nwhile sum(f) != sum(h):\n flag = False\n tmp = []\n for i in range(n):\n if i == n-1 and h[i] != f[i]:\n tmp.append(i)\n f = calc(f,tmp)\n ans+=1\n elif h[i] == f[i] and flag:\n f = calc(f,tmp)\n ans+=1\n break\n elif h[i] != f[i]:\n flag = True\n tmp.append(i)\nelse:\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s364009376', 's702558545'] | [3064.0, 3064.0] | [2103.0, 120.0] | [430, 603] |
p03147 | u634159866 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\n\nN = int(input())\nH = np.array(input().split(), dtype=np.int32)\n\ndef myfunc(left, right):\n if right<left:\n return 0\n idx = left+H[left:right+1].argmin()\n m = H[idx]\n H[left:right+1]-=m\n return m+myfunc(left, idx-1)+myfunc(right, idx+1)\n\nprint(myfunc(0, N-1))', 'N = int(input())\nH = np.array(input().split(), dtype=np.int32)\n\ndef myfunc(left, right):\n if right<left:\n return 0\n idx = left+H[left:right+1].argmin()\n m = H[idx]\n H[left:right+1]-=m\n return m+myfunc(left, idx-1)+myfunc(right, idx+1)\n\nprint(myfunc(0, N-1))', 'import numpy as np\n\nN = int(input())\nH = np.array(input().split(), dtype=np.int32)\n\ndef myfunc(left, right):\n if right<left:\n return 0\n idx = left+H[left:right+1].argmin()\n m = H[idx]\n H[left:right+1]-=m\n return m+myfunc(left, idx-1)+myfunc(idx+1, right)\n\nprint(myfunc(0, N-1))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s697441705', 's868515942', 's876100895'] | [12484.0, 3060.0, 14248.0] | [172.0, 17.0, 152.0] | [299, 279, 299] |
p03147 | u635182517 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['def water(list_a):\n if list_a == [0] * len(list_a):\n return 0\n \n elif 0 in list_a:\n n = list_a.index(0)\n return water(list_a[:n]) + water(list_a[n+1:])\n\n else:\n mini = min(list_a)\n for i in range(len(list_a)):\n list_a[i] += mini\n return water(list_a) + mini\n\nn = int(input())\nlist_h = list(map(int, input().split()))\nprint(list_h)\n', 'def water(list_a):\n if list_a == [0] * len(list_a):\n return 0\n \n elif 0 in list_a:\n n = list_a.index(0)\n return water(list_a[:n]) + water(list_a[n+1:])\n\n else:\n mini = min(list_a)\n for i in range(len(list_a)):\n list_a[i] -= mini\n return water(list_a) + mini\n\nn = int(input())\nlist_h = list(map(int, input().split()))\nprint(list_h)\n', 'def water(list_a):\n if list_a == [0] * len(list_a):\n return 0\n \n elif 0 in list_a:\n n = list_a.index(0)\n return water(list_a[:n]) + water(list_a[n+1:])\n\n else:\n mini = min(list_a)\n for i in range(len(list_a)):\n list_a[i] -= mini\n return water(list_a) + mini\n\nn = int(input())\nlist_h = list(map(int, input().split()))\nprint(water(list_h))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s675555375', 's922906020', 's902747472'] | [3060.0, 3060.0, 3192.0] | [17.0, 18.0, 18.0] | [396, 396, 402] |
p03147 | u644907318 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['def countA(A):\n global cnt\n if len(A)==1:\n cnt += A[0]\n else:\n amin = min(A)\n A = [A[i]-amin for i in range(len(A))]\n cnt += amin\n while A:\n if A[0]==0:\n A.pop(0)\n elif A[-1]==0:\n A.pop()\n else:break\n B = []\n for i in range(1,len(A)):\n if A[i]==0 and A[i-1]==0:\n B.append(i)\n C = []\n for i in range(len(A)):\n if i not in B:\n C.append(A[i])\n C0 = []\n for i in range(len(C)):\n if C[i]==0:\n C0.append(i)\n if len(C0)==0 and len(C)>0:\n countA(C)\n else:\n cur = 0\n for c in C0:\n countA(C[cur:c])\n cur = c+1\n countA(C[cur:])\n \nN = int(input())\nH = list(map(int,input().split()))\ncnt = 0\ncountA(H)\nprint(cnt)', 'def countA(A):\n global cnt\n if len(A)==1:\n cnt += A[0]\n else:\n amin = min(A)\n A = [A[i]-amin for i in range(len(A))]\n cnt += amin\n while A:\n if A[0]==0:\n A.pop(0)\n elif A[-1]==0:\n A.pop()\n else:break\n B = []\n for i in range(1,len(A)):\n if A[i]==0 and A[i-1]==0:\n B.append(i)\n C = []\n for i in range(len(A)):\n if i not in B:\n C.append(A[i])\n C0 = []\n for i in range(len(C)):\n if C[i]==0:\n C0.append(i)\n if len(C0)==0 and len(C)>0:\n countA(C)\n else:\n cur = 0\n for c in C0:\n countA(C[cur:c])\n cur = c+1\n if cur<len(C):\n countA(C[cur:])\n \nN = int(input())\nH = list(map(int,input().split()))\ncnt = 0\ncountA(H)\nprint(cnt)'] | ['Runtime Error', 'Accepted'] | ['s914546743', 's875759998'] | [3188.0, 3188.0] | [19.0, 19.0] | [925, 956] |
p03147 | u647796955 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import sys\nL = int(sys.stdin.readline().rstrip())\n\nif L == 1:\n h = int(sys.stdin.readline().rstrip())\nelse:\n h = list(map(int, sys.stdin.readline().rstrip().split()))\n\nL = N\nif L == 0:\n ans = 0\nelif L == 1:\n ans = N - h\nelif L == 2:\n ans = N - max(h)\n \nelse:\n grad1 = h[0] > h[1]\n p= 0\n v= 0\n if grad1:\n p += h[0]\n\n for n in range(2, L):\n grad2 = h[n-1] > h[n] \n if grad1 == grad2:\n continue\n elif grad2:\n p += h[n-1]\n else:\n v += h[n-1]\n grad1 = grad2\n \n if not grad1:\n p += h[n]\n \nans = p - v\nprint(ans)', 'N = int(sys.stdin.readline().rstrip())\nh = map(int, sys.stdin.readline().rstrip().split())\n\nL = len(h)\nif L == 0:\n ans = 0\nelif L < 1:\n ans = N - h[0]\nelif L < 2:\n ans = N - max(h)\n \nelse:\n grad1 = h[0] > h[1]\n if grad1:\n p = [h[0]]\n else:\n p = []\n \n v = []\n for n in range(2, L):\n grad2 = h[n-1] > h[n] \n if grad1 == grad2:\n continue\n elif grad2:\n p.append(h[n-1])\n else:\n v.append(h[n-1])\n grad1 = grad2\n \n if not grad1:\n p.append(h[n])\n \nans = sum(p) - sum(v)\nprint(ans)', 'import sys\nL = int(sys.stdin.readline().rstrip())\n \nh = list(map(int, sys.stdin.readline().rstrip().split()))\n \nif L == 0:\n ans = 0\nelif L == 1:\n ans = h[0]\nelif L == 2:\n ans = max(h)\n \nelse:\n grad1 = h[0] > h[1]\n p= 0\n v= 0\n if grad1:\n p += h[0]\n \n for n in range(2, L):\n grad2 = h[n-1] > h[n] \n if grad1 == grad2:\n continue\n elif grad2:\n p += h[n-1]\n else:\n v += h[n-1]\n grad1 = grad2\n \n if not grad1:\n p += h[n]\n \n ans = p - v\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s336871029', 's588431216', 's193528503'] | [3064.0, 3064.0, 3064.0] | [17.0, 17.0, 18.0] | [567, 539, 501] |
p03147 | u655975843 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input()) + 1\nl = list(map(int, input().split()))\nl.append(0)\n\ncount = 0\n\nfor i in range(n):\n\twhile(l[i] > 0):\n\t\tfor j in range(i + 1, n):\n\t\t\tif l[j] == 0:\n\t\t\t\tbreak\n\t\tfor k in range(i, j):\n\t\t\tl[k] -= 1\n\t\tcount += 1\n\t\tprint(l)\nprint(count)\n\n\n\n', 'n = int(input()) + 1\nl = list(map(int, input().split()))\nl.append(0)\n\ncount = 0\n\nfor i in range(n):\n\twhile(l[i] > 0):\n\t\tfor j in range(i + 1, n):\n\t\t\tif l[j] == 0:\n\t\t\t\tbreak\n\t\tfor k in range(i, j):\n\t\t\tl[k] -= 1\n\t\tcount += 1\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s531496278', 's462101214'] | [4724.0, 3060.0] | [64.0, 21.0] | [250, 235] |
p03147 | u664796535 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nH = [int(input()) for _ in range(N)]\ncost = 0\nfor i in range(N-1):\n if H[i] > H[i+1]:\n cost += (H[i] - H[i+1])\ncost += H[N-1]\nprint(cost)\n ', "N = int(input())\nH = list(map(int, input().split(' ')))\ncost = 0\nfor i in range(N-1):\n if H[i] > H[i+1]:\n cost += (H[i] - H[i+1])\ncost += H[N-1]\nprint(cost)\n "] | ['Runtime Error', 'Accepted'] | ['s143162770', 's358254504'] | [3056.0, 2940.0] | [17.0, 17.0] | [163, 165] |
p03147 | u668503853 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N=int(input())\nh=[0]+list(map(int,input().split()))\nc=0\nfor i in range(N):\n c+=max(h[i+1]-l[i],0)\nprint(c)', 'N=int(input())\nh=[0]+list(map(int,input().split()))\nc=0\nfor i in range(N):\n c+=max(h[i+1]-h[i],0)\nprint(c)'] | ['Runtime Error', 'Accepted'] | ['s635847295', 's176544832'] | [2940.0, 2940.0] | [18.0, 22.0] | [107, 107] |
p03147 | u677121387 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int,input().split()))\ncnt = 0\n\nfor i in range(max(h)):\n st = 1 if h[0] != 0 else 0\n for j in range(n):\n if st == 1:\n if h[j] == 0:\n cnt += 1\n st = 0\n else:\n h[j] -= 1\n else:\n if h[j] != 0:\n st = 1\n h[j] -= 1\n else:\n if st == 1:\n cnt += 1\nelse:\n ans = cnt', 'n = int(input())\nh = [int(i) for i in input().split()]\nans = h[0]\nfor i in range(1,n): ans += max(0,h[i]-h[i-1])\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s404550277', 's844593199'] | [3064.0, 9088.0] | [19.0, 28.0] | [436, 123] |
p03147 | u682467216 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['from math import floor, ceil, sqrt, factorial, log, gcd\nfrom itertools import accumulate, permutations, combinations, product, combinations_with_replacement\nfrom bisect import bisect_left, bisect_right\nfrom collections import Counter, defaultdict\nfrom heapq import heappop, heappush, heappushpop\nfrom copy import deepcopy\nimport numpy as np\nimport sys\nINF = float(\'inf\')\nmod = 10**9+7\n\n\ndef lcm(a, b): return a * b / gcd(a, b)\n\n# 1 2 3\n# a, b, c = LI()\n\n\ndef LI(): return list(map(int, sys.stdin.buffer.readline().split()))\n\n# a = I()\n\n\ndef I(): return int(sys.stdin.buffer.readline())\n\n\n# a, b = LS()\n\n\ndef LS(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\').split()\n\n# a = S()\n\n\ndef S(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\')\n\n# 2\n# 1\n# 2\n# [1, 2]\n\n\ndef IR(n): return [I() for i in range(n)]\n\n# 2\n# 1 2 3\n# 4 5 6\n# [[1,2,3], [4,5,6]]\n\n\ndef LIR(n): return [LI() for i in range(n)]\n\n# 2\n# abc\n\n\n\n\ndef SR(n): return [S() for i in range(n)]\n\n# 2\n\n\n\n\n\ndef LSR(n): return [LS() for i in range(n)]\n\n# 2\n# abcd\n# efgh\n# [[a,b,c,d], [e,f,g,h]]\n\n\ndef SRL(n): return [list(S()) for i in range(n)]\n\n\ndef main():\n n = I()\n h = list(LI())\n n = int(input())\n ans = h[0]\n for i in range(1, n):\n if h[i] > h[i-1]:\n ans += h[i] - h[i-1]\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'from math import floor, ceil, sqrt, factorial, log, gcd\nfrom itertools import accumulate, permutations, combinations, product, combinations_with_replacement\nfrom bisect import bisect_left, bisect_right\nfrom collections import Counter, defaultdict\nfrom heapq import heappop, heappush, heappushpop\nfrom copy import deepcopy\nimport numpy as np\nimport sys\nINF = float(\'inf\')\nmod = 10**9+7\n\n\ndef lcm(a, b): return a * b / gcd(a, b)\n\n# 1 2 3\n# a, b, c = LI()\n\n\ndef LI(): return list(map(int, sys.stdin.buffer.readline().split()))\n\n# a = I()\n\n\ndef I(): return int(sys.stdin.buffer.readline())\n\n\n# a, b = LS()\n\n\ndef LS(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\').split()\n\n# a = S()\n\n\ndef S(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\')\n\n# 2\n# 1\n# 2\n# [1, 2]\n\n\ndef IR(n): return [I() for i in range(n)]\n\n# 2\n# 1 2 3\n# 4 5 6\n# [[1,2,3], [4,5,6]]\n\n\ndef LIR(n): return [LI() for i in range(n)]\n\n# 2\n# abc\n\n\n\n\ndef SR(n): return [S() for i in range(n)]\n\n# 2\n\n\n\n\n\ndef LSR(n): return [LS() for i in range(n)]\n\n# 2\n# abcd\n# efgh\n# [[a,b,c,d], [e,f,g,h]]\n\n\ndef SRL(n): return [list(S()) for i in range(n)]\n\n\nans = []\n\n\ndef main():\n n = I()\n h = list(LI())\n n = int(input())\n ans = h[0]\n for i in range(1, n):\n if h[i] > h[i-1]:\n ans += h[i] - h[i-1]\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'from math import floor, ceil, sqrt, factorial, log, gcd\nfrom itertools import accumulate, permutations, combinations, product, combinations_with_replacement\nfrom bisect import bisect_left, bisect_right\nfrom collections import Counter, defaultdict\nfrom heapq import heappop, heappush, heappushpop\nimport copy\nimport numpy as np\nimport sys\nINF = float(\'inf\')\nmod = 10**9+7\n\n\ndef lcm(a, b): return a * b / gcd(a, b)\n\n# 1 2 3\n# a, b, c = LI()\n\n\ndef LI(): return list(map(int, sys.stdin.buffer.readline().split()))\n\n# a = I()\n\n\ndef I(): return int(sys.stdin.buffer.readline())\n\n\n# a, b = LS()\n\n\ndef LS(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\').split()\n\n# a = S()\n\n\ndef S(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\')\n\n# 2\n# 1\n# 2\n# [1, 2]\n\n\ndef IR(n): return [I() for i in range(n)]\n\n# 2\n# 1 2 3\n# 4 5 6\n# [[1,2,3], [4,5,6]]\n\n\ndef LIR(n): return [LI() for i in range(n)]\n\n# 2\n# abc\n\n\n\n\ndef SR(n): return [S() for i in range(n)]\n\n# 2\n\n\n\n\n\ndef LSR(n): return [LS() for i in range(n)]\n\n# 2\n# abcd\n# efgh\n# [[a,b,c,d], [e,f,g,h]]\n\n\ndef SRL(n): return [list(S()) for i in range(n)]\n\n\ndef main():\n n = I()\n h = list(LI())\n n = int(input())\n ans = h[0]\n for i in range(1, n):\n if h[i] > h[i-1]:\n ans += h[i] - h[i-1]\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'from math import floor, ceil, sqrt, factorial, log, gcd\nfrom itertools import accumulate, permutations, combinations, product, combinations_with_replacement\nfrom bisect import bisect_left, bisect_right\nfrom collections import Counter, defaultdict\nfrom heapq import heappop, heappush, heappushpop\nimport copy\nimport numpy as np\nimport sys\nINF = float(\'inf\')\nmod = 10**9+7\n\n\ndef lcm(a, b): return a * b / gcd(a, b)\n\n# 1 2 3\n# a, b, c = LI()\n\n\ndef LI(): return list(map(int, sys.stdin.buffer.readline().split()))\n\n# a = I()\n\n\ndef I(): return int(sys.stdin.buffer.readline())\n\n\n# a, b = LS()\n\n\ndef LS(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\').split()\n\n# a = S()\n\n\ndef S(): return sys.stdin.buffer.readline().rstrip().decode(\'utf-8\')\n\n# 2\n# 1\n# 2\n# [1, 2]\n\n\ndef IR(n): return [I() for i in range(n)]\n\n# 2\n# 1 2 3\n# 4 5 6\n# [[1,2,3], [4,5,6]]\n\n\ndef LIR(n): return [LI() for i in range(n)]\n\n# 2\n# abc\n\n\n\n\ndef SR(n): return [S() for i in range(n)]\n\n# 2\n\n\n\n\n\ndef LSR(n): return [LS() for i in range(n)]\n\n# 2\n# abcd\n# efgh\n# [[a,b,c,d], [e,f,g,h]]\n\n\ndef SRL(n): return [list(S()) for i in range(n)]\n\n\ndef main():\n n = I()\n h = list(LI())\n ans = h[0]\n for i in range(1, n):\n if h[i] > h[i-1]:\n ans += h[i] - h[i-1]\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s027105237', 's047115147', 's894179012', 's321442774'] | [27216.0, 27068.0, 27160.0, 27112.0] | [113.0, 112.0, 115.0, 117.0] | [1413, 1424, 1399, 1378] |
p03147 | u691018832 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int,input().split()))\n\nans = 0\ncheck = 0\nprint(len(h))\nfor i in h:\n if check < i:\n ans += i-check\n check = i\n\nprint(ans)\n', 'n = int(input())\nh = list(map(int, input().split()))\nans = 0\ncheak = 0\nif n == 1:\n ans += h[0] \nelif n != 0:\n for i in range(1, n-1):\n if h[i-1] > h[i] and h[i+1] > h[i]:\n cheak += h[i]\n elif h[i-1] < h[i] and h[i+1] < h[i]:\n ans += h[i]\n\n if h[n-1] >= h[n-2]:\n ans += h[n-1]\nans -= cheak\nprint(ans)', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10 ** 7)\n\nn, *h = map(int, read().split())\nans = h[0]\nfor bf, af in zip(h, h[1:]):\n if af > bf:\n ans += af - bf\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s112950002', 's299535562', 's146632941'] | [2940.0, 3064.0, 2940.0] | [17.0, 17.0, 17.0] | [164, 354, 271] |
p03147 | u698416089 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = input().split()\n\nmizuyari = 0\nfor i in range(int(sorted(h)[n-1])):\n maenohana = False\n mizuyari += thismizuyari\n thismizuyari = 0\n for j in range(n):\n if not maenohana and i+1<=int(h[j]):\n thismizuyari += 1\n maenohana = i+1<=int(h[j])\nprint(mizuyari)', 'n = int(input())\nh = list(map(int,input().split()))\n \nmizuyari = 0\nfor i in range(sorted(h)[n-1]):\n maenohana = False\n for j in range(n):\n if not maenohana and i+1<=h[j]:\n mizuyari += 1\n maenohana = i+1<=h[j]\nprint(mizuyari)'] | ['Runtime Error', 'Accepted'] | ['s677611370', 's415833241'] | [3060.0, 3060.0] | [17.0, 20.0] | [308, 255] |
p03147 | u705621008 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['s = int(input())\na = list(map(int, input().split()))\n\nincFlg = True \nbefore_height = 0\nsum = 0\n\nfor i in range(len(a)-1):\n \n if a[i] > a[i+1]:\n \n if incFlg:\n sum += a[i] - before_height\n incFlg = False\n \n else:\n # before_height = a[i]\n \n else:\n if not incFlg:\n before_height = a[i]\n incFlg = True\n\nif incFlg:\n sum += a[len(a)-1] - before_height\n\nprint(sum)\n', 's = int(input())\na = list(map(int, input().split()))\n\nincFlg = True \nbefore_height = 0\nsum = 0\n\nfor i in range(len(a)-1):\n \n if a[i] > a[i+1]:\n \n if incFlg:\n sum += a[i] - before_height\n incFlg = False\n \n # else:\n # # before_height = a[i]\n \n else:\n if not incFlg:\n before_height = a[i]\n incFlg = True\n\nif incFlg:\n sum += a[len(a)-1] - before_height\n\nprint(sum)\n'] | ['Runtime Error', 'Accepted'] | ['s523635921', 's312669482'] | [3064.0, 3060.0] | [17.0, 18.0] | [568, 572] |
p03147 | u708615801 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['num = int(input())\ntargets = map(int, input().split())\ntargets = list(targets)\n\n\nwater_cnt = 0\ndef exe_water(init_state):\n # break condition\n if sum(init_state) == 0:\n return\n temp_water_cnt = min(init_state)\n water_cnt += temp_water_cnt\n\n lowest = temp_water_cnt\n # init sub_state\n sub_state = []\n for h in init_state:\n substracted_h = h - lowest\n if substracted_h != 0:\n sub_state.append(substracted_h)\n else:\n exe_water(sub_state)\n \n sub_state = []\n\nexe_water(targets)\nprint(water_cnt)\n', 'num = int(input())\ntargets = map(int, input().split())\ntargets = list(targets)\n\n\nglobal water_cnt\nwater_cnt = 0\ndef exe_water(init_state):\n global water_cnt\n # break condition\n if sum(init_state) == 0:\n return\n temp_water_cnt = min(init_state)\n water_cnt += temp_water_cnt\n\n lowest = temp_water_cnt\n # init sub_state\n sub_state = []\n for h in init_state:\n substracted_h = h - lowest\n if substracted_h != 0:\n sub_state.append(substracted_h)\n else:\n exe_water(sub_state)\n \n sub_state = []\n # end case where no trailing 0\n exe_water(sub_state)\n\nexe_water(targets)\nprint(water_cnt)\n'] | ['Runtime Error', 'Accepted'] | ['s274807852', 's196225981'] | [3060.0, 3064.0] | [17.0, 18.0] | [611, 709] |
p03147 | u711238850 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import sys\nsys.setrecursionlimit(1000000)\ndef watering(l,a,b):\n if b-a <= 1:\n return l[a]\n \n c = 0\n t = a\n \n mi = min(l[a:b])\n for i in range(a,b):\n l[i] -= mi\n \n for i in range(a,b):\n if l[i]==0:\n c += watering(l,t,i)\n t=i+1\n c += watering(l,t,b)\n \n return c+mi\n\nn = int(input())\nh = list(map(int,input().split()))\n\nprint(watering(h,0,n))', 'import sys\nsys.setrecursionlimit(1000000)\ndef watering(l,a,b):\n if b==a:\n return 0\n if b-a <= 1:\n return l[a]\n \n c = 0\n t = a\n \n mi = min(l[a:b])\n for i in range(a,b):\n l[i] -= mi\n \n for i in range(a,b):\n if l[i]==0:\n c += watering(l,t,i)\n t=i+1\n c += watering(l,t,b)\n \n return c+mi\n\nn = int(input())\nh = list(map(int,input().split()))\n\nprint(watering(h,0,n))'] | ['Runtime Error', 'Accepted'] | ['s986848077', 's309147375'] | [3064.0, 3064.0] | [18.0, 18.0] | [376, 400] |
p03147 | u714378447 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import sys\nimport copy\nN=int(input())\nH = [int(x) for x in input().split()]\n\nif N==1:\n print(H[0])\n sys.exit()\n\ncnt=0\nwhile True:\n f=True\n for h in H:\n if h!=0:\n f=False\n break\n if f:\n break\n\n H_new = copy.copy(H)\n if H[0]!=0 and H[1]==0:\n cnt+=1\n H_new[0]-=1\n for i in range(1,len(H)):\n if H[i-1]==0 and H[i]!=0:\n cnt+=1\n if H_new[i]!=0:\n H_new[i]-=1\n H = copy.copy(H_new)\n\n\nprint(cnt)\n', 'import sys\nimport copy\nN=int(input())\nH = [int(x) for x in input().split()]\n\nif N==1:\n print(H[0])\n sys.exit()\n\ncnt=0\nwhile True:\n f=True\n for h in H:\n if h!=0:\n f=False\n break\n if f:\n break\n\n H_new = copy.copy(H)\n if H[0]!=0:\n if H[0]!=0:\n cnt+=1\n H_new[0]-=1\n for i in range(1,len(H)):\n if H[i-1]==0 and H[i]!=0:\n cnt+=1\n if H_new[i]!=0:\n H_new[i]-=1\n H = copy.copy(H_new)\n\n\nprint(cnt)\n'] | ['Wrong Answer', 'Accepted'] | ['s863526293', 's297277969'] | [3444.0, 3444.0] | [27.0, 25.0] | [500, 512] |
p03147 | u724742135 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['from math import factorial\nfrom sys import exit, stdin\nN = int(stdin.readline().rstrip())\nH = [int(_) for _ in stdin.readline().rstrip().split()]\nans = 0\nfor i in range(1,n):\n if H[i-1] > H[i]:\n ans += H[i-1]-H[i]\nans += H[-1]\nprint(ans)', 'from math import factorial\nfrom sys import exit, stdin\nN = int(stdin.readline().rstrip())\nH = [int(_) for _ in stdin.readline().rstrip().split()]\nans = 0\nfor i in range(1,N):\n if H[i-1] > H[i]:\n ans += H[i-1]-H[i]\nans += H[-1]\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s032643065', 's494305390'] | [3060.0, 3188.0] | [17.0, 19.0] | [247, 247] |
p03147 | u729938879 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nheight = list(map(int, input().split())) \nwater_count = 0 \nwhile True:\n index = [i for i, v in enumerate(height) if v >0] \n \n \n min_index = index[0] \n max_index = index[0] \n \n while True:\n if max_index+1 in index:\n max_index += 1\n else:\n break\n \n # print("index: {}".format(index)) \n \n water_amount = min(height[min_index:max_index+1]) \n for flower in range(min_index, max_index+1):\n height[flower] -= water_amount \n \n # print("height:{} ".format(height))\n water_count +=water_amount\n \n if np.sum(height) ==0: \n break\nprint(water_count)', 'N = int(input()) \nheight = list(map(int, input().split())) \nwater_count = 0 \nwhile True:\n index = [i for i, v in enumerate(height) if v >0] \n \n if len(index) == len(height): \n height -= 1 \n water_count += 1\n \n else:\n \n min_index = index[0] \n max_index = index[0] \n \n while True:\n if (max_index+1) in index:\n max_index += 1\n else:\n break\n \n for flower in range(min_index, max_index+1):\n height[flower] -= 1 \n water_count += 1 \n \n if sum(height) == 0: \n break\nprint(water_count)', 'def solve(height):\n \n water_count = 0 \n\n while True:\n index = [i for i, v in enumerate(height) if v >0] \n \n \n min_index = index[0] \n max_index = index[0] \n \n while True:\n if (max_index+1) in index:\n max_index += 1\n else:\n break\n \n for flower in range(min_index, max_index+1):\n height[flower] -= 1 \n water_count += 1 \n \n if sum(height) == 0: \n break\n print(water_count)\n \ndef solve_zero(height): \n print(0)\n\nif __name__ == "__main__":\n N = int(input()) \n height = list(map(int, input().split())) \n if sum(height) == 0:\n solve_zero(height)\n else:\n solve(height)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s253218401', 's334192988', 's610188073'] | [3064.0, 3064.0, 3064.0] | [18.0, 55.0, 53.0] | [995, 977, 1102] |
p03147 | u732061897 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nH = list(map(int, input().split()))\nans = 0\nactive = 0\nfor i in range(N):\n h = H[i]\n ans += min(0, h - active)\n active = h\nprint(ans)\n', 'N = int(input())\nH = list(map(int, input().split()))\nans = 0\nactive = 0\nfor i in range(N):\n h = H[i]\n ans += min(0, h - active)\n active = h\nprint(ans)\n', 'N = int(input())\nH = list(map(int, input().split()))\nans = H[0]\nactive = H[0]\nfor i in range(1,N):\n h = H[i]\n ans += max(0, h - active)\n active = h\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s012824037', 's835408298', 's112929968'] | [9084.0, 9084.0, 9160.0] | [26.0, 29.0, 29.0] | [160, 160, 168] |
p03147 | u732468087 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = map(int, input().split())\nh = list(map(int, input().split()))\n\nloc_max = h[0]\ncount = 0\n\nfor i in range(1, N):\n if h[i] >= loc_max:\n loc_max = h[i]\n if h[i] < h[i-1]:\n count = count + loc_max - h[i]\n loc_max = 0\n if i == N-1:\n count = count + h[i]\n\nprint(count)', 'N = int(input())\nh = list(map(int, input().split()))\n\ncount = 0\n\nfor i in range(N-1):\n if h[i] > h[i+1]:\n count = count + h[i] - h[i+1]\n\ncount = count + h[N-1]\n\nprint(count)'] | ['Runtime Error', 'Accepted'] | ['s328329965', 's541748881'] | [3064.0, 3060.0] | [18.0, 17.0] | [302, 183] |
p03147 | u748311048 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int, input().split()))\ncnt = int()\nfor i in reversed(range(1, max(h)+1)):\n tmp = list()\n for j in h:\n if i <= j:\n tmp.append(1)\n else:\n tmp.append(0)\n # print(tmp)\n for j in range(1, n):\n if tmp[j]-tmp[j-1] == 1:\n cnt += 1\n\nprint(cnt)\n', 'n = int(input())\nh = list(map(int, input().split()))\ncnt = int()\nfor i in reversed(range(1, max(h)+1)):\n tmp = list()\n for j in h:\n if i <= j:\n tmp.append(1)\n else:\n tmp.append(0)\n #print(tmp)\n if tmp[0]==1:\n cnt += 1\n for j in range(1, n):\n if tmp[j]-tmp[j-1] == 1:\n cnt += 1\n\nprint(cnt)\n'] | ['Wrong Answer', 'Accepted'] | ['s362713039', 's966630156'] | [3060.0, 3060.0] | [20.0, 21.0] | [331, 365] |
p03147 | u762420987 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\nN = int(input())\nhlist = np.array([_ for _ in map(int,input().split())])\n\nmax = np.max(hlist)\nmin = np.min(hlist)\nL = len(hlist)\n\nnewlist = np.zeros_like(hlist)\nnum = 0\n\nlist = []\n\n\n\nfor i in range(max+1):\n over = np.sum(hlist >= i)\n print(over)\n if over == L:\n continue\n num += over\n\nprint("ans",num)\n', 'N = int(input())\nhlist = list(map(int, input().split()))\ndef count_island(height):\n res = 0\n sink = True\n for h in hlist:\n if sink and h > height:\n res += 1\n sink = False\n if h <= height:\n sink = True\n return res\n\nans = 0\nfor height in range(max(hlist)):\n ans += count_island(height)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s392515497', 's028359153'] | [12496.0, 3060.0] | [150.0, 18.0] | [340, 356] |
p03147 | u763968347 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nh = list(map(int,input().split()))\n\ndef dfs(L):\n for i,l in enumerate(L):\n if l != 0:\n break\n L = L[i:N]\n s = 0\n res = 0\n for i,l in enumerate(L):\n print(i,s)\n if l == 0:\n L_ = [l_-1 for l_ in L[s:i]]\n s = i+1\n if len(L_) != 0:\n res += 1\n res += dfs(L_)\n elif i == len(L)-1:\n L_ = [l_-1 for l_ in L[s:len(L)]]\n s = i+1\n if len(L_) != 0:\n res += 1\n res += dfs(L_)\n return res\n\nif sum(h) == 0:\n print(0)\nelse:\n print(dfs(h))', 'N = int(input())\nh = list(map(int,input().split()))\n\ndef dfs(L):\n for i,l in enumerate(L):\n if l != 0:\n break\n L = L[i:N]\n s = 0\n res = 0\n for i,l in enumerate(L):\n if l == 0:\n L_ = [l_-1 for l_ in L[s:i]]\n print(s,i,L_)\n res += 1\n s = i+1\n if sum(L_) != 0:\n res += dfs(L_)\n elif i == len(L)-1:\n L_ = [l_-1 for l_ in L[s:len(L)]]\n print(s,i,L_)\n res += 1\n s = i+1\n if sum(L_) != 0:\n res += dfs(L_)\n return res\n\nif sum(h) == 0:\n print(0)\nelse:\n print(dfs(h))', 'N = int(input())\nh = list(map(int,input().split()))\n\ndef dfs(L):\n for i,l in enumerate(L):\n if l != 0:\n break\n L = L[i:N]\n s = 0\n res = 0\n for i,l in enumerate(L):\n if l == 0:\n L_ = [l_-1 for l_ in L[s:i]]\n s = i+1\n if len(L_) != 0:\n res += 1\n res += dfs(L_)\n elif i == len(L)-1:\n L_ = [l_-1 for l_ in L[s:len(L)]]\n s = i+1\n if len(L_) != 0:\n res += 1\n res += dfs(L_)\n return res\n\nif sum(h) == 0:\n print(0)\nelse:\n print(dfs(h))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s446655849', 's827832069', 's032434420'] | [3852.0, 3652.0, 3188.0] | [33.0, 37.0, 24.0] | [628, 653, 609] |
p03147 | u764956288 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["N = input()\nstr_h = input()\n\nfls = flowers(str_h)\nls_fls = fls.str_split0()\nwater = 0\n\nwhile(len(ls_fls)>0):\n #print(f'ls_fls = {ls_fls}')\n temp_ls_fls = []\n for fls in ls_fls:\n if len(fls)<=2:\n water += max([int(s) for s in fls])\n continue\n else:\n _fls = flowers(' '.join(fls))\n _fls.minimize()\n _ls_fls = _fls.str_split0()\n water += _fls.water\n temp_ls_fls += _ls_fls\n flg=1\n ls_fls = temp_ls_fls\nprint(water)", "class flowers:\n def __init__(self, str_h):\n self.str = str_h.split()\n self.int = []\n self.min = 0\n self.water = 0\n \n self.update_int()\n self.update_min()\n \n def update_str(self):\n self.str = list(map(str, self.int))\n return\n\n def update_int(self):\n self.int = list(map(int, self.str))\n return\n \n def update_min(self):\n self.min = min(self.int)\n return\n \n def minimize(self):\n self.int = [n-self.min for n in self.int]\n self.water += self.min\n self.update_str()\n self.min = 0\n return\n \n def str_split0(self):\n idxs = [-1] + [i for i,n in enumerate(self.int) if n==0]\n if len(idxs)==1:\n return [self.str]\n else:\n temp_ls = []\n for i in range(len(idxs)-1):\n s = self.str[idxs[i]+1:idxs[i+1]]\n if len(s)>0: temp_ls.append(s)\n if self.int[-1]!=0:\n temp_ls.append(self.str[idxs[-1]+1:])\n return temp_ls\n\nN = input()\nstr_h = input()\n\nfls = flowers(str_h)\nls_fls = fls.str_split0()\nwater = 0\n\nwhile(len(ls_fls)>0):\n #print(f'ls_fls = {ls_fls}')\n temp_ls_fls = []\n for fls in ls_fls:\n if len(fls)<=2:\n water += max([int(s) for s in fls])\n continue\n else:\n _fls = flowers(' '.join(fls))\n _fls.minimize()\n _ls_fls = _fls.str_split0()\n water += _fls.water\n temp_ls_fls += _ls_fls\n flg=1\n ls_fls = temp_ls_fls\nprint(water)\n"] | ['Runtime Error', 'Accepted'] | ['s510652290', 's346120565'] | [3064.0, 3064.0] | [19.0, 21.0] | [525, 1597] |
p03147 | u773686010 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['# https://atcoder.jp/contests/abc116/tasks/abc116_c C - Grand Garden\nn=int(input())\nTree_List=list(map(int,input().split()))\n\nct =0\nfor i in range(n):\n while Tree_List[i] != 0:\n \n if i == n-1:\n Tree_List[i] -= 1\n \n else:\n \n k=i+1\n while Tree_List[k] != 0 and k < n-1: \n k += 1\n Tree_List[i:k]=map(lambda x:x-1,Tree_List[i:k])\n \n ct += 1\n\n \nprint(ct)', '# https://atcoder.jp/contests/abc116/tasks/abc116_c C - Grand Garden\nn=int(input())\nTree_List=list(map(int,input().split()))\n\nct =0\nfor i in range(n):\n while Tree_List[i] != 0:\n \n if i == n-1:\n Tree_List[i] -= 1\n \n else:\n \n k = i + 1\n while Tree_List[k] != 0: \n k+=1\n if k == n:\n break\n Tree_List[i:k]=map(lambda x:x-1,Tree_List[i:k])\n \n ct += 1\n \nprint(ct)'] | ['Wrong Answer', 'Accepted'] | ['s286800246', 's949218125'] | [3064.0, 3064.0] | [22.0, 23.0] | [669, 711] |
p03147 | u780475861 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nc, *lst = [int(i) for i in input().split()]\nfor i in range(1, n):\n if lst[i] > lst[i - 1]:\n c += lst[i] - lst[i - 1]\nprint(c)', 'n = int(input())\nlst = [int(i) for i in input().split()]\nc = lst[0]\nfor i in range(1, n):\n if lst[i] > lst[i - 1]:\n c += lst[i] - lst[i - 1]\nprint(c)'] | ['Runtime Error', 'Accepted'] | ['s511214039', 's353941121'] | [2940.0, 2940.0] | [17.0, 17.0] | [148, 155] |
p03147 | u781021311 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nl = list(map(int, input().split())) + [0]\nans = 0\nmin_v = 101\ncurr = 0\nlast = -1\ncount = 0\n\nfor _ in range(n+1):\n for i in range(n+1):\n curr = l[i]\n if curr == 0:\n for j in range(last+1, i):\n l[j] -= min_v\n\n if i > last + 1:\n count += min_v\n\n last = i\n min_v = 101\n curr = 0\n elif curr < min_v:\n min_v = curr\n print(l)\n last = -1\n\nprint(count)\n\n\n\n', 'n = int(input())\nl = list(map(int, input().split())) + [0]\nans = 0\nmin_v = 1000\ncurr = 0\nlast = -1\ncount = 0\n\nfor _ in range(n+1):\n for i in range(n+1):\n curr = l[i]\n if curr == 0:\n for j in range(last+1, i):\n l[j] -= min_v\n\n if i > last + 1:\n count += min_v\n\n last = i\n min_v = 1000\n curr = 0\n elif curr < min_v:\n min_v = curr\n last = -1\n\nprint(count)\n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s290506244', 's030005924'] | [6516.0, 3064.0] | [103.0, 23.0] | [494, 479] |
p03147 | u795021383 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nlisth = list(map(int, input().split()))\nlistans = [listh[0]]\nfor n in range(1,N-1):\n if (listh[n+1]-listh[n])*(listh[n]-listh[n-1])<=0:\n listans.append(listh[n])\nlistans.append(listh[N-1]) \n#print(listans)\nl =len(listans)\nlistans2 = []\nfor n in range(l-1):\n if listans[n] == listans[n+1]:\n pass\n else:\n listans2.append(listans[n])\nlistans2.append(listans[l-1]) \n#print(listans2) \nL = len(listans2)\n#print(L)\nlistodd = [listans2[x] for x in range(L) if x%2 ==1]\n#print(listodd)\nlisteven = [listans2[x] for x in range(L) if x%2 ==0]\n\nif L%2 == 0:\n if listeven[0]>listodd[0]:\n del listodd[-1]\n ans = sum(listeven)-sum(listodd)\n print(ans)\n\n else: \n del listeven[0]\n ans = sum(listodd)-sum(listeven) \n print(ans)\n\nelse: \n if listeven[0]>listodd[0]:\n ans = sum(listeven)-sum(listodd)\n print(ans)\n\n else:\n del listeven[-1]\n if len(listeven)>0\n del listeven[0]\n ans = sum(listodd)-sum(listeven)\n print(ans)\n ', 'N = int(input())\nlisth = list(map(int, input().split()))\nlistans = [listh[0]]\nfor n in range(1,N-1):\n if (listh[n+1]-listh[n])*(listh[n]-listh[n-1])<=0:\n listans.append(listh[n])\nlistans.append(listh[N-1]) \n#print(listans)\nl =len(listans)\nlistans2 = []\nfor n in range(l-1):\n if listans[n] == listans[n+1]:\n pass\n else:\n listans2.append(listans[n])\nlistans2.append(listans[l-1]) \n#print(listans2) \nL = len(listans2)\n#print(L)\nlistans3 = [listans2[0]]\nfor n in range(1,L-1):\n if (listans2[n+1]-listans2[n])*(listans2[n]-listans2[n-1])<=0:\n listans3.append(listans2[n])\nlistans3.append(listans2[L-1]) \n#print(listans3)\nll =len(listans3)\nlistodd = [listans3[x] for x in range(ll) if x%2 ==1]\n#print(listodd)\nlisteven = [listans3[x] for x in range(ll) if x%2 ==0]\n\nif len(listodd) == 0:\n print(listeven[0])\nelif ll%2 == 0:\n if listeven[0]>listodd[0]:\n del listodd[-1]\n ans = sum(listeven)-sum(listodd)\n print(ans)\n\n else: \n del listeven[0]\n ans = sum(listodd)-sum(listeven) \n print(ans)\n\nelse: \n if listeven[0]>listodd[0]:\n ans = sum(listeven)-sum(listodd)\n print(ans)\n\n else:\n del listeven[-1]\n if len(listeven) >= 1:\n del listeven[0]\n ans = sum(listodd)-sum(listeven)\n print(ans)\n '] | ['Runtime Error', 'Accepted'] | ['s483456039', 's928851052'] | [3064.0, 3188.0] | [17.0, 18.0] | [1097, 1381] |
p03147 | u802977614 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nh=list(map(int,input().split()))\nans=0\n\ndef f(li):\n global ans\n \n \n if li==[]:\n del li\n return\n \n \n min_num=min(li)\n if min(li)>0:\n count+=min(li)\n li=list(map(lambda x: x-min(li), li))\n li=[li[:li.index(0)],li[li.index(0)+1:]]\n f(li[0])\n f(li[1])\n\nf(h)\nprint(count)', 'n=int(input())\nh=list(map(int,input().split()))\nans=0\n\ndef f(li):\n global ans\n \n \n if li==[]:\n del li\n return\n \n \n min_num=min(li)\n if min(li)>0:\n ans+=min(li)\n li=list(map(lambda x: x-min(li), li))\n li=[li[:li.index(0)],li[li.index(0)+1:]]\n f(li[0])\n f(li[1])\n\nf(h)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s106531567', 's276132676'] | [3064.0, 3064.0] | [18.0, 27.0] | [324, 320] |
p03147 | u821284362 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nh_ls = list(map(int,input().split(" ")))\n\nh_ls = np.array(h_ls)\nn = 0\nh_len = len(h_ls)\nwhile max(h_ls)!=0:\n max_ind = h_ls.argmax()\n d = 0\n while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:\n d+=1\n h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1\n n+=1\n print(h_ls)\n\nprint(n)\n', 'N = int(input())\nh_ls = list(map(int,input().split(" ")))\n\nh_ls = np.array(h_ls)\nn = 0\nh_len = len(h_ls)\nwhile max(h_ls)!=0:\n max_ind = h_ls.argmax()\n d = 0\n while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:\n d+=1\n h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1\n n+=1\n\nprint(n)\n', 'import numpy as np\n\nN = int(input())\nh_ls = list(map(int,input().split(" ")))\n\nh_ls = np.array(h_ls)\nn = 0\nh_len = len(h_ls)\nwhile max(h_ls)!=0:\n max_ind = h_ls.argmax()\n d = 0\n while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:\n d+=1\n h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1\n n+=1\n\nprint(n)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s110411645', 's910788870', 's882617979'] | [3060.0, 3060.0, 12508.0] | [17.0, 17.0, 293.0] | [339, 323, 343] |
p03147 | u821712904 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=ini(input())\nh=[int(i) for i input().split()]\nj=0\nans=0\nwhile True:\n if h[0]>j:\n ans+=1\n for i in range(1,n):\n if h[i-1]<=j and h [i]>j:\n ans+=1\n j+=1\n if j==max(h):\n break\nprint(ans) ', 'n=int(input())\nh=[int(i) for i input().split()]\nj=0\nans=0\nwhile True:\n if h[0]>j:\n ans+=1\n for i in range(1,n):\n if h[i-1]<=j and h [i]>j:\n ans+=1\n j+=1\n if j==max(h):\n break\nprint(ans) ', 'n=int(input())\nh=[int(i) for i in input().split()]\nj=0\nans=0\nwhile j<max(h):\n if h[0]>j:\n ans+=1\n for i in range(1,n):\n if h[i-1]<=j and h [i]>j:\n ans+=1\n j+=1\nprint(ans) '] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s416262194', 's814769945', 's331858146'] | [2940.0, 2940.0, 3060.0] | [17.0, 17.0, 19.0] | [204, 204, 185] |
p03147 | u841222846 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\n\nn = int(input())\nh = list(map(int, input().split(" ")))\n\nh = np.array(h)\n\ncount = 0\nwhile(sum(h) != 0):\n s = 200\n e = n\n for i in range(n):\n if(s == 200):\n if(h[i] != 0): s = i\n elif(h[i] == 0):\n e = i\n break\n\n count += min(h[s:e])\n h[s:e] -= min(h[s:e])\n\n print(h)\n\nprint(count)', 'import numpy as np\n\nn = int(input())\nh = list(map(int, input().split(" ")))\n\nh = np.array(h)\n\ncount = 0\nwhile(sum(h) != 0):\n s = 200\n e = n\n for i in range(n):\n if(s == 200):\n if(h[i] != 0): s = i\n elif(h[i] == 0):\n e = i\n break\n\n count += min(h[s:e])\n h[s:e] -= min(h[s:e])\n\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s717056651', 's547175565'] | [21784.0, 18856.0] | [312.0, 429.0] | [364, 350] |
p03147 | u875855656 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nl=[int(i) for i in input().split()]\nv=sum(l)\ne=0\nfor i in range(max(l)):\n ef=0\n for j in l:\n print(i,j)\n if j>i:\n ef+=1\n else:\n if ef>0:\n e+=ef-1\n ef=0\n if ef>1:\n e+=ef-1\nprint(v-e)\n', 'n=int(input())\nl=[int(i) for i in input().split()]\nv=sum(l)\ne=0\nfor i in range(max(l)):\n ef=0\n for j in l:\n if j>i:\n ef+=1\n else:\n if ef>0:\n e+=ef-1\n ef=0\n if ef>1:\n e+=ef-1\nprint(v-e)\n'] | ['Wrong Answer', 'Accepted'] | ['s570952174', 's719542675'] | [3628.0, 3060.0] | [32.0, 19.0] | [234, 219] |
p03147 | u879674287 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\nN = input()\nh = list(map(int, input().split()))\n\na = np.zeros(N)\nh_min = min(h)\ntmp = (h >= h_min+1)*1\n\ncnt = 0\nfor idx, i in enumerate(tmp):\n if idx==0:\n a0 = i\n if i==1:\n cnt+=1\n continue\n \n if idx==a0:\n continue\n else:\n cnt+=1\nelse:\n if i==0:\n cnt-=1\n \nprint(cnt+h_min)', 'import numpy as np\nN = int(input())\nh = np.array(list(map(int, input().split())))\n\na = np.zeros(N)\nh_min = min(h)\ntmp = (h >= h_min+1)*1\n\ncnt = 0\nfor idx, i in enumerate(tmp):\n if idx==0:\n a0 = i\n if i==1:\n cnt+=1\n continue\n \n if idx==a0:\n continue\n else:\n cnt+=1\nelse:\n if i==0:\n cnt-=1\n \nprint(cnt+h_min)', 'import numpy as np\nN = input()\nh = np.array(list(map(int, input().split())))\n\na = np.zeros(N)\nh_min = min(h)\ntmp = (h >= h_min+1)*1\n\ncnt = 0\nfor idx, i in enumerate(tmp):\n if idx==0:\n a0 = i\n if i==1:\n cnt+=1\n continue\n \n if idx==a0:\n continue\n else:\n cnt+=1\nelse:\n if i==0:\n cnt-=1\n \nprint(cnt+h_min)', 'import numpy as np\nN = int(input())\nh = np.array(list(map(int, input().split())))\n\n# N = 8\n# h = np.array(list(map(int, "4 23 75 0 23 96 50 100".split())))\n\na = np.zeros(N)\nh_min = min(h)\nh_max = max(h)\nn_loop = h_max - h_min\n\ncnt = 0\nfor zzz in range(n_loop):\n tmp = (h >= h_min+1+zzz)*1\n# print(tmp)\n for idx, i in enumerate(tmp):\n if idx==0:\n first = i\n a0 = i\n continue\n \n if i==a0:\n continue\n else:\n if i==1:\n cnt+=1\n a0 = i\n else:\n if first==1:\n cnt+=1\n \nprint(cnt+h_min)'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s003657714', 's724535125', 's929114546', 's618391641'] | [12472.0, 18084.0, 12380.0, 12508.0] | [152.0, 275.0, 151.0, 161.0] | [370, 385, 380, 633] |
p03147 | u879870653 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nH = list(map(int,input().split()))\nH.append(0)\nans = 0\n\nmi = min(H)\nfor i in range(N) :\n H[i] -= mi\nans += mi\nprint(H,ans)\nfor i in range(N) :\n a = H[i]\n H[i] = 0\n for j in range(i+1,N+1) :\n if a <= H[j] :\n H[j] -= a\n else :\n \n ans += a-H[j]\n a = H[j]\n break\n if a == min(H[i:]) :\n ans += a\n \n #print(H)\n #print(ans)\nprint(ans)\n', 'N = int(input())\nL = list(map(int,input().split()))\n\nans = 0\n\nwhile len(L) :\n if L[0] == 0 :\n L.pop(0)\n else :\n ans += 1\n for i in range(len(L)) :\n if L[i] != 0 :\n L[i] -= 1\n else :\n break\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s695048111', 's857641534'] | [3064.0, 2940.0] | [27.0, 22.0] | [457, 279] |
p03147 | u891422384 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ["le = int(input())\nll=list(map(int, input().split(' ')))\n\n\nres=0\n\nwhile max(ll)>0:\n i=0\n while i<le:\n if ll[i]==0: \n i+=1\n else:\n res+=1\n while i<le and ll[i]>0:\n ll[i]-=1\n i+=1", 'le = int(input())\nll = list(map(int, input().split()))\n \nres = h[0]\nfor i in range(1, ll):\n if(ll[i-1] < ll[i]): res += ll[i]-ll[i-1]\nprint(res)', 'le = int(input())\nll = list(map(int, input().split()))\n \nres = ll[0]\nfor i in range(1, le):\n if(ll[i-1] < ll[i]): res += ll[i]-ll[i-1]\nprint(res)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s676527781', 's821550519', 's551076972'] | [3060.0, 3060.0, 3060.0] | [21.0, 18.0, 18.0] | [213, 147, 148] |
p03147 | u901598613 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nl=list(map(int,input().split()))\nfor t in range(len(l)):\n l[t]-=1\nans=1\nf=1\nm=max(l)\nfor j in range(m):\n for i in range(len(l)):\n if l[i]==0:\n f=1\n elif f==0:\n l[i]-=1\n else:\n ans+=1\n l[i]-=1\n f=0\n print(l,ans)\nprint(ans)\n', 'n=int(input())\nl=list(map(int,input().split()))\nans=0\nf=1\nm=max(l)\nfor j in range(m):\n for i in range(n):\n if l[i]==0:\n f=1\n elif f==0:\n l[i]-=1\n else:\n ans+=1\n l[i]-=1\n f=0\n f=1\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s800635582', 's878234261'] | [7284.0, 3064.0] | [109.0, 19.0] | [326, 271] |
p03147 | u905510147 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nh = list(map(int, input().split()))\n\nans = 0\nwhile max(h):\n current_hight = 0\n for i in range(len(h)):\n if not h[i]:\n if not current_hight:\n continue\n else:\n break\n elif h[i] < current_hight:\n break\n else:\n current_hight = h[i]\n h[i] -= 1\n ans += 1\n if ans == 75:\n\nprint(ans)', 'N = int(input())\nh = list(map(int, input().split()))\n\nans = 0\nwhile max(h):\n current_hight = 0\n for i in range(len(h)):\n if not h[i]:\n if not current_hight:\n continue\n else:\n break\n elif h[i] < current_hight:\n break\n else:\n current_hight = h[i]\n h[i] -= 1\n ans += 1\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s512256221', 's379335751'] | [3064.0, 3188.0] | [17.0, 54.0] | [410, 392] |
p03147 | u905582793 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nh = list(map(int, input().split()))\nans = 0\nfor i in range(N-1):\n if h[i+1] > h[i]:\n ans += h[i+1]-h[i]\nprint(ans)', 'N = int(input())\nh = list(map(int, input().split()))\nans = h[0]\nfor i in range(N-1):\n if h[i+1] > h[i]:\n ans += h[i+1]-h[i]\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s380194072', 's616847139'] | [2940.0, 2940.0] | [18.0, 17.0] | [135, 138] |
p03147 | u910540337 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['"main.py" 5L, 116C written\ndef calc_watering_num(h, offset, left, right):\n if left > right:\n return 0\n min_h = None\n min_h_indices = []\n for i in range(left, right + 1):\n if min_h is None or min_h > h[i] - offset:\n min_h = h[i] - offset\n min_h_indices = [i]\n elif min_h == h[i] - offset:\n min_h_indices.append(i)\n if len(min_h_indices) == right - left + 1:\n return min_h\n num = min_h\n prev = left\n for i in min_h_indices:\n num += calc_watering_num(h, offset + min_h, prev, i - 1)\n prev = i + 1\n num += calc_watering_num(h, offset + min_h, prev, right)\n return num\n\n\ninput()\nh = [int(v) for v in input().split()]\nprint(calc_watering_num(h, 0, 0, len(h) - 1))', 'def calc_watering_num(h, offset, left, right):\n if left > right:\n return 0\n min_h = None\n min_h_indices = []\n for i in range(left, right + 1):\n if min_h is None or min_h > h[i] - offset:\n min_h = h[i] - offset\n min_h_indices = [i]\n elif min_h == h[i] - offset:\n min_h_indices.append(i)\n if len(min_h_indices) == right - left + 1:\n return min_h\n num = min_h\n prev = left\n for i in min_h_indices:\n num += calc_watering_num(h, offset + min_h, prev, i - 1)\n prev = i + 1\n num += calc_watering_num(h, offset + min_h, prev, right)\n return num\n\n\ninput()\nh = [int(v) for v in input().split()]\nprint(calc_watering_num(h, 0, 0, len(h) - 1))'] | ['Runtime Error', 'Accepted'] | ['s333787588', 's922258775'] | [2940.0, 3064.0] | [17.0, 18.0] | [886, 859] |
p03147 | u917733926 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N = int(input())\nH = list(int(i) for i in input().split())\n\n\ndef count(h):\n print(h)\n if len(h) != 0:\n output = 0\n min_elem = min(h)\n output += min_elem\n for index in range(0, len(h)):\n h[index] -= min_elem\n tmp_h = []\n for index in range(0, len(h)):\n if (h[index] > 0):\n tmp_h.append(h[index])\n else:\n output += count(tmp_h)\n tmp_h = []\n output += count(tmp_h)\n print(output)\n return output\n else:\n return 0\n\nh = H\nprint(count(h))', 'N = int(input())\nH = list(int(i) for i in input().split())\n\n\ndef count(h):\n if len(h) != 0:\n output = 0\n min_elem = min(h)\n output += min_elem\n for index in range(0, len(h)):\n h[index] -= min_elem\n tmp_h = []\n for index in range(0, len(h)):\n if (h[index] > 0):\n tmp_h.append(h[index])\n else:\n output += count(tmp_h)\n tmp_h = []\n output += count(tmp_h)\n return output\n else:\n return 0\n\nh = H\nprint(count(h))'] | ['Wrong Answer', 'Accepted'] | ['s730776077', 's956220481'] | [3064.0, 3064.0] | [19.0, 20.0] | [626, 591] |
p03147 | u918117985 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['\n\n#include <algorithm>\nusing namespace std;\n\nint f(vector<int> v, int i, int a) {\n vector<int>::iterator maxIt = max_element(v.begin(), v.end());\n vector<int>::iterator minIt = min_element(v.begin(), v.end());\n if (v.size() == 0){\n return a;\n }\n if(*maxIt == *minIt) {\n return a + (*minIt) - i;\n }\n a+=*minIt-i;\n i = *minIt;\n size_t minIndex = distance(v.begin(), minIt);\n if (minIndex == 0) {\n vector<int> vec;\n copy(next(v.begin()), v.end(), back_inserter(vec));\n a = f(vec, i, a);\n } else if (minIndex == v.size()) {\n vector<int> vec;\n copy(v.begin(), prev(v.end()), back_inserter(vec));\n a = f(vec, i, a);\n } else {\n vector<int> vec1;\n copy(v.begin(), minIt, back_inserter(vec1));\n a = f(vec1, i, a);\n vector<int> vec2;\n copy(next(minIt), v.end(), back_inserter(vec2));\n a = f(vec2, i, a);\n }\n return a;\n}\n\n\nint main() {\n int n;\n cin >> n;\n vector<int> v(n);\n for (int i=0; i<n; i++) {\n cin >> v[i];\n }\n int a = f(v, 0, 0);\n\n return 0;\n}', 'n = int(input())\nh = list(map(int, input().split()))\n\nmaxNum = max(h)\ncountNumber = 0\ncountWatering = 0\nisfinished = False\nfor c in range(1, maxNum+1):\n array = []\n for index, num in enumerate(h):\n if (num >= c):\n array.append(index)\n if (len(array) == 0 or c > maxNum):\n break\n startIndex = 0\n beforeVlaue = array[0]-1\n for a in array:\n if (a-1 != beforeVlaue):\n countWatering+=1\n if (a == array[-1]):\n countWatering+=1\n beforeVlaue = a\n \nprint(countWatering)'] | ['Runtime Error', 'Accepted'] | ['s451727942', 's261947630'] | [2940.0, 3064.0] | [17.0, 21.0] | [1145, 550] |
p03147 | u919235786 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nh=list(map(int,input.split()))\nhm=max(h)\nt=1\nfor i in range(hm,-1,-1):\n for j in range(n)\n if h[j]=i:\n ans+=t\n t=0\n else:\n t=1\n\nprint(ans)\n', 'n=int(input())\nh=list(map(int,input().split()))\nhm=max(h)\nt=1\nans=0\nfor i in range(hm,-1,-1):\n for j in range(n):\n if h[j]=i:\n ans+=t\n t=0\n else:\n t=1\n\nprint(ans)\n', 'n=int(input())\nh=list(map(int,input().split()))\nhm=max(h)\nt=1\nans=0\nfor i in range(hm,-1,-1):\n for j in range(n):\n if h[j]==i:\n ans+=t\n t=0\n else:\n t=1\n\nprint(ans)\n', 'n=int(input())\nh=list(map(int,input.split()))\nhm=max(h)\nt=1\nfor i in range(hm,-1,-1):\n for j in range(n):\n if h[j]=i:\n ans+=t\n t=0\n else:\n t=1\n\nprint(ans)\n', 'n=int(input())\nh=list(map(int,input().split()))\nhm=max(h)\n\nans=0\nfor i in range(hm,-1,-1):\n t=1\n for j in range(n):\n if h[j]=i:\n ans+=t\n t=0\n else:\n t=1\n\nprint(ans)\n', 'n=int(input())\nh=list(map(int,input.split()))\nhm=max(h)\nt=1\nans=0\nfor i in range(hm,-1,-1):\n for j in range(n):\n if h[j]=i:\n ans+=t\n t=0\n else:\n t=1\n\nprint(ans)\n', 'n=int(input())\nh=list(map(int,input().split()))\nhm=max(h)\n\nans=0\nfor i in range(hm,0,-1):\n t=1\n for j in range(n):\n if h[j]>=i:\n ans+=t\n t=0\n else:\n t=1\n\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s140441314', 's181307180', 's455838442', 's577152052', 's638009179', 's817878933', 's327259124'] | [9028.0, 8824.0, 9180.0, 8964.0, 9032.0, 8992.0, 9036.0] | [29.0, 27.0, 29.0, 27.0, 27.0, 24.0, 26.0] | [204, 213, 214, 205, 218, 211, 218] |
p03147 | u919689206 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['# -*- coding: utf-8 -*-\n\n\n\n\ndef mizuyari(ary):\n n = 0\n ary2 = distinctAry(ary)\n \n \n if min(ary) > 0:\n n += 1 + mizuyari([s - 1 for s in ary2])\n \n \n else:\n print(ary2)\n \n return n\n\n\ndef distinctAry(ary):\n \n for i, j in enumerate(ary):\n \n if i + 1 >= len(ary):\n break;\n else:\n if (ary[i] == ary[i + 1]):\n del(ary[i])\n return ary\n\n#main start\nimport copy\n\nn = int(input())\nary = [int(s) for s in input().split()]\n\nmizuyari(ary)\n\n', 'n = int(input())\nl = [int(i) for i in input().split()]\n\ndef out(l):\n ll = bunkatu(l)\n \n res = 0\n \n for l in ll:\n \n \n l2 = [i - 1 for i in l]\n \n \n if not l2:\n continue\n \n if max(l2) > 0:\n res += 1 + out(l2)\n else:\n res += 1\n \n return res\n\ndef bunkatu(l):\n \n s = 0 #start\n ll = []\n \n for k, v in enumerate(l) :\n \n if v <= 0 :\n ll.append(l[s:k])\n s = k + 1\n \n else:\n if s != k + 1:\n ll.append(l[s:k + 1])\n return ll\n\n\nprint(out(l))'] | ['Wrong Answer', 'Accepted'] | ['s895893313', 's081629989'] | [3572.0, 3064.0] | [28.0, 25.0] | [674, 744] |
p03147 | u921027074 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input())\nh=list(map(int,input().split()))\nans=0\nwhile sum(h)>0:\n for i in range(n):\n if i<n-1 and h[i]>0 and h[i+1]==0:\n ans+=1\n else:\n if i==N-1 and h[i]>0:\n ans+=1\n if h[i]>0:\n h[i]-=1\nprint(ans) ', 'n=int(input())\nh=list(map(int,input().spliy()))\nans=0\nwhile sum(h)>0:\n for i in range(n):\n if i<n-1 and h[i]>0 and h[i+1]==0:\n ans+=1\n else:\n if i==N-1 and h[i]>0:\n ans+=1\n if h[i]>0:\n h[i]-=1\nprint(ans) ', 'n=int(input())\nh=list(map(int,input().split()))\n\nans=0\nwhile sum(h)>0:\n for i in range(n):\n if i<n-1 and h[i]>0 and h[i+1]==0:\n ans+=1\n else:\n if i==N-1 and h[i]>0:\n ans+=1\n if h[i]>0:\n h[i]-=1\nprint(ans) ', 'N=int(input())\nh=list(map(int,input().split()))\n\nans=0\nwhile sum(h)>0:\n for i in range(N):\n if i<N-1 and h[i]>0 and h[i+1]==0:\n ans+=1\n else:\n if i==N-1 and h[i]>0:\n ans+=1\n if h[i]>0:\n h[i]-=1\nprint(ans) '] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s038821843', 's075508751', 's772317257', 's743832002'] | [3060.0, 3060.0, 3060.0, 3060.0] | [17.0, 18.0, 17.0, 21.0] | [241, 241, 242, 242] |
p03147 | u923712635 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['def mizuyari2(l):\n count = 0\n stopper = 0\n\n for i in l:\n stopper+=i \n if(stopper == 0):\n return 0 \n\n if(l[0]!=0):\n count+=1\n for i in range(len(l)-1):\n if(l[i]==0 and l[i+1]!=0):\n count+=1\n\n for index,i in enumerate(l): \n l[index]-=1\n if(l[index]<0):\n l[index]=0\n\n return count+mizuyari2(l)\n\nN = int(input())\nh = []\n\nfor i in range(N):\n h.append(int(input()))\n\nprint(mizuyari2(h))', 'def mizuyari2(l):\n count = 0\n stopper = 0\n\n for i in l:\n stopper+=i \n if(stopper == 0):\n return 0 \n\n if(l[0]!=0):\n count+=1\n for i in range(len(l)-1):\n if(l[i]==0 and l[i+1]!=0):\n count+=1\n if(l[len(l)-2]==0 and l[len(l)-1!=0]):\n count+=1\n\n for index,i in enumerate(l): \n l[index]-=1\n if(l[index]<0):\n l[index]=0\n\n return count+mizuyari2(l)\n\nN = int(input())\nh = []\n\nfor i in range(N):\n h.append(int(input()))\n\nprint(mizuyari2(h))', 'def mizuyari2(l):\n count = 0\n stopper = 0\n\n for i in l:\n stopper+=i \n if(stopper == 0):\n return 0 \n\n if(l[0]!=0):\n count+=1\n for i in range(len(l)-1):\n if(l[i]==0 and l[i+1]!=0):\n count+=1\n\n for index,i in enumerate(l): \n l[index]-=1\n if(l[index]<0):\n l[index]=0\n\n return count+mizuyari2(l)\n\nN = int(input())\nh = []\n\nfor i in range(N):\n h.append(int(input()))\n\nprint(mizuyari2(h))', "import array\ndef count_mizuyari(l):\n count = 0\n arr = array.array('i',[0])\n arr.extend(l)\n for i in range(len(arr)-1):\n if(arr[i]==0 and arr[i+1]!=0):\n count += 1\n return count\n \n\ndef mizuyari2(l):\n count = 0\n stopper = 0\n\n \n for i in l:\n stopper+=i \n if(stopper == 0):\n return 0 \n else: \n count=count_mizuyari(l)\n for index,i in enumerate(l): \n l[index]-=1\n if(l[index]<0):\n l[index]=0\n\n return count+mizuyari2(l)\n\nN = int(input())\nh = array.array('i')\n\nli = input().rstrip().split()\nfor i in li:\n h.append(int(i))\n\n\nprint(mizuyari2(h))\n"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s076904225', 's378039690', 's700333118', 's526687461'] | [3064.0, 3064.0, 3064.0, 3064.0] | [17.0, 17.0, 17.0, 22.0] | [488, 548, 488, 699] |
p03147 | u927534107 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\ns = list(map(int,input().split()))\ns = [i-1 for i in s]\nans = 0\nwhile(sum(s)!=-n):\n s_new=[i.replace("-1","a") for i in map(str,s)]\n print(s_new)\n s_join = \'\'.join(s_new)\n non = s_join.split("a")\n num = len([x for x in non if x])\n ans += num\n s = [max(i-1,-1) for i in s]\nprint(ans)', 'n = int(input())\ns = list(map(int,input().split()))\ns = [i-1 for i in s]\nans = 0\nwhile(sum(s)!=-n):\n s_new=[i.replace("-1","a") for i in map(str,s)]\n s_join = \'\'.join(s_new)\n non = s_join.split("a")\n num = len([x for x in non if x])\n ans += num\n s = [max(i-1,-1) for i in s]\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s136156767', 's090586892'] | [3064.0, 3064.0] | [24.0, 23.0] | [320, 303] |
p03147 | u929313378 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import sys\nimport numpy as np\nimport collections\n\ndef parse(inp):\n N=int(next(inp))\n H=np.array(next(inp).split(),dtype=int)\n return H\n \ndef split(H):\n Splited=np.array([],dtype=int)\n SplitPoint=[]\n for i in range(len(H)):\n if(H[i]==0):\n SplitPoint.append(i)\n \n if(SplitPoint==[]):\n Splited=np.array([H])\n return Splited\n \n Splited=np.append(Splited,np.split(H,SplitPoint))\n \n \n \n for i in range(len(Splited)):\n if(Splited[i].size==0):\n continue\n elif(Splited[i][0]==0):\n Splited[i]=np.delete(Splited[i],[0])\n \n return Splited\n \ndef main(H):\n H=collections.deque(H)\n# print(H)\n\n answer=0\n \n while H:\n Hnow=H.popleft()\n if(Hnow.size==0):\n continue\n# print("now: ",Hnow)\n Hnowmin=Hnow.min()\n answer+=Hnowmin\n for i in range(len(Hnow)):\n Hnow[i]=Hnow[i]-Hnowmin\n# print("decreased: ",Hnow)\n for i in range(len(split(Hnow))):\n if(split(Hnow)[i].size!=0):\n# print("append: ",split(Hnow)[i])\n H.append(split(Hnow)[i])\n# print("H: ",H)\n return answer\n\nprint(main(split(parse(sys.stdin))))', 'import sys\nimport numpy as np\nimport collections\n\ndef parse(inp):\n N=int(next(inp))\n H=np.array(next(inp).split(),dtype=int)\n return H\n \ndef split(H):\n Splited=np.array([],dtype=int)\n SplitPoint=[]\n for i in range(len(H)):\n if(H[i]==0):\n SplitPoint.append(i)\n \n if(SplitPoint==[]):\n Splited=np.array([H])\n return Splited\n if(SplitPoint[0]==len(H)-1):\n Splited=np.array([np.delete([H],len(H)-1)])\n return Splited\n \n Splited=np.append(Splited,np.split(H,SplitPoint))\n \n for i in range(len(Splited)):\n if(Splited[i].size==0):\n continue\n elif(Splited[i][0]==0):\n Splited[i]=np.delete(Splited[i],[0])\n \n return Splited\n \ndef main(H):\n H=collections.deque(H)\n# print(H)\n\n answer=0\n \n while H:\n Hnow=H.popleft()\n if(Hnow.size==0):\n continue\n# print("now: ",Hnow)\n Hnowmin=Hnow.min()\n answer+=Hnowmin\n for i in range(len(Hnow)):\n Hnow[i]=Hnow[i]-Hnowmin\n# print("decreased: ",Hnow)\n for i in range(len(split(Hnow))):\n if(split(Hnow)[i].size!=0):\n# print("append: ",split(Hnow)[i])\n H.append(split(Hnow)[i])\n# print("H: ",H)\n return answer\n\nprint(main(split(parse(sys.stdin))))', 'import sys\nimport numpy as np\nimport collections\n\ndef parse(inp):\n N=int(next(inp))\n H=np.array(next(inp).split(),dtype=int)\n return H\n \ndef split(H):\n Splited=np.array([],dtype=int)\n SplitPoint=[]\n for i in range(len(H)):\n if(H[i]==0):\n SplitPoint.append(i)\n \n if(SplitPoint==[]):\n Splited=np.array([H])\n return Splited\n \n Splited=np.split(H,SplitPoint)\n \n \n \n for i in range(len(Splited)):\n if(Splited[i].size==0):\n continue\n elif(Splited[i][0]==0):\n Splited[i]=np.delete(Splited[i],[0])\n \n return Splited\n \ndef main(H):\n H=collections.deque(H)\n# print(H)\n\n answer=0\n \n while H:\n Hnow=H.popleft()\n if(Hnow.size==0):\n continue\n# print("now: ",Hnow)\n Hnowmin=Hnow.min()\n answer+=Hnowmin\n for i in range(len(Hnow)):\n Hnow[i]=Hnow[i]-Hnowmin\n# print("decreased: ",Hnow)\n for i in range(len(split(Hnow))):\n if(split(Hnow)[i].size!=0):\n# print("append: ",split(Hnow)[i])\n H.append(split(Hnow)[i])\n# print("H: ",H)\n return answer\n\nprint(main(split(parse(sys.stdin))))\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s946785445', 's954870614', 's266332526'] | [13420.0, 17888.0, 13328.0] | [219.0, 261.0, 212.0] | [1274, 1360, 1256] |
p03147 | u930862022 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int, input().split()))\n\ncount = 0\n\nfor i in range(n): \n while h[i] >= 1:\n wid = 0\n for l in range(i,n):\n if h[l] >= 1:\n wid = wid + 1\n else:\n break\n print(wid)\n \n for k in range(wid):\n h[i + k] = h[i+k] - 1\n print(h)\n count = count + 1\n\nprint(count)', 'n = int(input())\nh = list(map(int, input().split()))\n\ncount = 0\n\nfor i in range(n): \n while h[i] >= 1:\n wid = 0\n for l in range(i,n):\n if h[l] >= 1:\n wid = wid + 1\n else:\n break\n \n \n for k in range(wid):\n h[i + k] = h[i+k] - 1\n \n count = count + 1\n\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s326234725', 's572198523'] | [4724.0, 3060.0] | [68.0, 23.0] | [429, 411] |
p03147 | u932868243 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['import numpy as np\nn=int(input())\nh=list(map(int,input().split()))\nh=np.array(h)\nans=0\nwhile True:\n for i in range(n):\n k=n-i\n cnt=0\n for j in range(1,k):\n if all(hh!=0 for hh in h[i:i+j+1]):\n cnt+=1\n h[i:i+cnt+1]=-1\n ans+=1\nprint(ans)', 'n=int(input())\nh=list(map(int,input().split()))\nh=np.array(h)\nans=0\nwhile True:\n if all(hhh==0 for hhh in h):\n print(ans)\n exit()\n for i in range(n):\n k=n-i\n cnt=0\n for j in range(1,k):\n if all(hh!=0 for hh in h[i:i+j+1]):\n cnt+=1\n h[i:i+cnt+1]=-1\n ans+=1\n', 'n=int(input())\nh=list(map(int,input().split()))\nsum=h[0]\nfor i in range(n-1):\n if h[i+1]>h[i]:\n sum+=h[i+1]-h[i]\nprint(sum)'] | ['Time Limit Exceeded', 'Runtime Error', 'Accepted'] | ['s285180927', 's732644402', 's652663093'] | [14440.0, 3060.0, 3060.0] | [2108.0, 17.0, 17.0] | [263, 281, 127] |
p03147 | u934740772 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n=int(input()\nh=list(map(int,input().split()))\nans=0\nfor i in range(max(h)):\n cnt=0\n for j in range(n):\n if h[j]>=i+1:\n cnt+=1\n elif j==n-1:\n ans+=cnt\n else:\n ans+=cnt\n cnt=0\nprint(ans)', 'n=int(input())\nh=list(map(int,input().split()))\nh.append(0)\nans=0\nfor i in range(max(h)):\n cnt=0\n for j in range(n+1):\n if h[j]>=i+1:\n cnt+=1\n else:\n if cnt>=1:\n ans+=1\n cnt=0\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s221370029', 's901447759'] | [2940.0, 3060.0] | [17.0, 19.0] | [300, 254] |
p03147 | u934788990 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int,input().split()))\ncount = h[0]\nfor i in range(n-1):\n if h[i+1]>h[i]:\n count += h[i+1]-h[i]\nprint(cnt)\n', 'n = int(input())\nh = list(map(int,input().split()))\ncount = h[0]\nfor i in range(N-1):\n if h[i+1]>h[i]:\n count += h[i+1]-h[i]\nprint(cnt)', 'N = int(input())\nh = list(map(int,input().split()))\ncnt = h[0]\nfor i in range(N-1):\n if h[i+1]>h[i]:\n cnt += h[i+1]-h[i]\nprint(cnt)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s030418421', 's697399370', 's409902493'] | [2940.0, 3060.0, 3064.0] | [18.0, 17.0, 17.0] | [146, 145, 136] |
p03147 | u934868410 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = list(map(int,input().split()))\nans = 0\nwhile True:\n water = False\n for i in range(n):\n if h[i] > 0:\n h[i] -= 1\n water = True\n elif water:\n ans += 1\n water = False\n if water:\n ans += 1\nprint(ans)', 'n = int(input())\nh = list(map(int,input().split()))\nans = 0\nwhile True:\n water = False\n finish = True\n for i in range(n):\n if h[i] > 0:\n h[i] -= 1\n water = True\n finish = False\n elif water:\n ans += 1\n water = False\n if water:\n ans += 1\n if finish:\n break\nprint(ans)'] | ['Time Limit Exceeded', 'Accepted'] | ['s091053636', 's657296096'] | [3060.0, 3064.0] | [2104.0, 19.0] | [247, 307] |
p03147 | u936985471 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['N=int(input())\nh=list(map(int,input().split()))\n\n\n\n\n\n\n\n\n\ndef water(currentnum, currentlist): \n global count\n\n \n \n partlist = [] \n \n for i in range(currentnum):\n if currentlist[i] != 0:\n partlist.append(currentlist[i]) \n else: \n \n if len(partlist)==0:\n partlist=[]\n else: \n water(len(partlist),partlist)\n \n partlist=[]\n \n newlist=[]\n print("")\n print(partlist)\n if len(partlist)==len(currentlist): \n print(currentlist)\n count = count + 1\n \n for i in range(currentnum):\n newlist.append(currentlist[i]-1)\n water(len(newlist),newlist)\n print(newlist)\n print(count)\n\n\ncount=0\nwater(N,h)\nprint(count)\n', 'n=int(input())\nh=[0]+list(map(int,input().split()))\nans=0\nfor i in range(n):\n ans += max(h[i+1]-h[i],0)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s595544285', 's331572532'] | [3500.0, 2940.0] | [46.0, 17.0] | [1327, 115] |
p03147 | u937529125 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['a = [int(i) for i in input().split()] \nn = 0\nnum = a[0]\nfor i in a:\n max = a[0]\n \n \n if i > a[n-1] and n > 0:\n num += (i-a[n-1])\n n += 1\nprint(num) \n \n \n ', 'l = input()\na = [int(i) for i in input().split()] \nn = 0\nnum = a[0]\nfor i in a:\n max = a[0]\n \n \n if i > a[n-1] and n > 0:\n num += (i-a[n-1])\n n += 1\nprint(num) \n \n \n '] | ['Wrong Answer', 'Accepted'] | ['s573587187', 's980502349'] | [2940.0, 3064.0] | [18.0, 18.0] | [166, 178] |
p03147 | u939702463 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['n = int(input())\nh = map(int, input().split())\n\nans = 0\nfor i in range(1, n):\n d = h[i] - h[i-1]\n if d > 0:\n ans += d\nprint(ans)', 'n = int(input())\nh = list(map(int, input().split()))\n \nans = h[0]\nfor i in range(1, n):\n d = h[i] - h[i-1]\n if d > 0:\n ans += d\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s444686336', 's883019966'] | [2940.0, 3060.0] | [18.0, 17.0] | [133, 143] |
p03147 | u941434715 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['#coding: utf-8\nimport math\nimport heapq\nimport bisect\nimport numpy as np\n#from scipy.misc import comb\n\nN = int(input())\nh = list(map(int, input().split()))\n\nans += h[0]\nbase = h[0]\nfor i in range(1,N):\n ans += max(h[i]-base,0)\n base = h[i]\n\nprint(ans)', '#coding: utf-8\nimport math\nimport heapq\nimport bisect\nimport numpy as np\n#from scipy.misc import comb\n\nN = int(input())\nh = list(map(int, input().split()))\n\nans = h[0]\nbase = h[0]\nfor i in range(1,N):\n ans += max(h[i]-base,0)\n base = h[i]\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s186389689', 's278499107'] | [12212.0, 20300.0] | [150.0, 323.0] | [257, 256] |
p03147 | u941438707 | 2,000 | 1,048,576 | In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. | ['\nn=int(input())\nh=list(map(int, input().split()))\nsum=0\nfor i in range(max(h)):\n if 0 not in h:\n h=[i-1 if i>0 else 0 for i in h]\n sum+=1\n # print(h,1)\n else:\n count0=[i for i, j in enumerate(h) if j==0]\n a=count0.copy() \n b=count0.copy()\n a.pop(0)\n b.pop(-1)\n c=[x-y for(x,y) in zip(a,b)]\n sum = sum + len(c)-c.count(1)\n print(count0)\n if count0[0]>0 and count0[-1]<n-1:\n sum +=2\n # print(1)\n elif count0[0]>0 or count0[-1]<n-1:\n sum +=1\n # print(2)\n else:\n sum +=0\n h=[i-1 if i>0 else 0 for i in h]\n # print(h,2)\nprint(sum) \n ', 'n=int(input())\nh=list(map(int, input().split()))\nsum=0\nfor i in range(max(h)):\n if 0 not in h:\n h=[i-1 if i>0 else 0 for i in h]\n sum+=1\n else:\n count0=[i for i, j in enumerate(h) if j==0]\n a=count0.copy() \n b=count0.copy()\n del a[0]\n del b[-1]\n c=[x-y for(x,y) in zip(a,b)]\u3000\n sum = sum + len(c)-c.count(1)\n if count0[0]>0 and count0[-1]<n-1:\n sum +=2\n elif count0[0]>0 or count0[-1]<n-1:\n sum +=1\n else:\n sum +=0\n h=[i-1 if i>0 else 0 for i in h]\nprint(sum) ', 'n,*h=map(int,open(0).read().split());h+=[0];print(sum(max(h[i]-h[i+1],0)for i in range(n)))'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s261196658', 's458165833', 's628950411'] | [3064.0, 3188.0, 2940.0] | [20.0, 22.0, 17.0] | [874, 686, 91] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.