Submission #12122679


Source Code Expand

Copy
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array(read().split(), np.int64)
I = np.argsort(A)[::-1].tolist()
A = A[I].tolist()

dp = np.zeros(1, np.int64)

for n, (i, x) in enumerate(zip(I, A)):
    newdp = np.zeros(len(dp) + 1, np.int64)
    left_ind = np.arange(len(dp))
    right_ind = N - 1 - n + left_ind
    left_cost = x * np.abs(left_ind - i)
    right_cost = x * np.abs(right_ind - i)
    np.maximum(newdp[:-1], dp + right_cost, out=newdp[:-1])
    np.maximum(newdp[1:], dp + left_cost, out=newdp[1:])
    dp = newdp

print(dp.max())

Submission Info

Submission Time
Task E - Active Infants
User maspy
Language Python (3.8.2)
Score 500
Code Size 686 Byte
Status
Exec Time 141 ms
Memory 27992 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 Sample_01.txt, Sample_02.txt, Sample_03.txt
FULL 500 / 500 Sample_01.txt, Sample_02.txt, Sample_03.txt, maxhand_01.txt, maxhand_02.txt, maxhand_03.txt, maxhand_04.txt, maxhand_05.txt, maxrand_01.txt, maxrand_02.txt, maxrand_03.txt, maxrand_04.txt, maxrand_05.txt, minhand_01.txt, minhand_02.txt, minhand_03.txt, minhand_04.txt, minrand_01.txt, minrand_02.txt, minrand_03.txt, minrand_04.txt, ni_01.txt, rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt
Case Name Status Exec Time Memory
Sample_01.txt 100 ms 27048 KB
Sample_02.txt 98 ms 27296 KB
Sample_03.txt 99 ms 27152 KB
maxhand_01.txt 135 ms 27844 KB
maxhand_02.txt 134 ms 27796 KB
maxhand_03.txt 134 ms 27988 KB
maxhand_04.txt 137 ms 27772 KB
maxhand_05.txt 135 ms 27784 KB
maxrand_01.txt 134 ms 27736 KB
maxrand_02.txt 134 ms 27692 KB
maxrand_03.txt 138 ms 27888 KB
maxrand_04.txt 136 ms 27992 KB
maxrand_05.txt 141 ms 27784 KB
minhand_01.txt 101 ms 27072 KB
minhand_02.txt 100 ms 27040 KB
minhand_03.txt 98 ms 27056 KB
minhand_04.txt 101 ms 27016 KB
minrand_01.txt 97 ms 27276 KB
minrand_02.txt 99 ms 27116 KB
minrand_03.txt 102 ms 27232 KB
minrand_04.txt 101 ms 27260 KB
ni_01.txt 99 ms 27004 KB
rand_01.txt 114 ms 27668 KB
rand_02.txt 136 ms 27760 KB
rand_03.txt 125 ms 27704 KB
rand_04.txt 108 ms 27592 KB