Code Submission Evaluation System Login

HIIT Open 2018

Start:2018-05-26 11:00:00
End:2018-05-26 16:00:00
 

Tasks | Messages | Scoreboard | Statistics


CSES - HIIT Open 2018 - Results
History
2018-05-26 15:28:15
Task:Buy Low, Sell High
Sender:El Numero Uno
Submission time:2018-05-26 15:28:15
Language:Python3
Status:READY
Result:TIME LIMIT EXCEEDED

Test results

testverdicttime (s)
#1TIME LIMIT EXCEEDED-- / 1.00details
#2TIME LIMIT EXCEEDED-- / 1.00details
#3TIME LIMIT EXCEEDED-- / 1.00details
#4TIME LIMIT EXCEEDED-- / 1.00details
#5TIME LIMIT EXCEEDED-- / 1.00details
#6ACCEPTED0.03 / 1.00details
#7ACCEPTED0.05 / 1.00details
#8ACCEPTED0.06 / 1.00details
#9TIME LIMIT EXCEEDED-- / 1.00details

Code

def parseM(m, v, reverse):
	n = []
	for pair in reversed(m):
		added = False
		if (v < pair[0] and not reverse) or (v > pair[0] and reverse):
			added = True
			n.append([v, v, 0])
			if pair[2] > 0:
				n.append(pair)
		if (v > pair[1] and not reverse) or (v < pair[1] and reverse):
			added = True
			n.append([pair[0], v, abs(v - pair[0])])
		if not added:
			n.append(pair)
		while len(n) > 1 and n[-1][2] <= n[0][2]:
			n.pop()
	return list(reversed(n))
	
 
def getAns(l, reverse=False):
	m = [[[l[0],l[0],0]]]
	for i in range(1, len(l)):
		v = l[i]
		m.append(parseM(m[-1], v, reverse))
	return m
			


input()
l = list(map(int, input().split()))
d1 = getAns(l)
d2 = list(reversed(getAns(list(reversed(l)), True)))
m = []
for i in range(len(l)):
	m.append(d1[i][0][2] + d2[i][0][2])
print(max(m))

Test details

Test 1

Verdict: TIME LIMIT EXCEEDED

input
500000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
view   save

correct output
0
view   save

user output
(no output)
view   save

Test 2

Verdict: TIME LIMIT EXCEEDED

input
500000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
view   save

correct output
499999
view   save

user output
(no output)
view   save

Test 3

Verdict: TIME LIMIT EXCEEDED

input
500000
500000 499999 499998 499997 49...
view   save

correct output
0
view   save

user output
(no output)
view   save

Test 4

Verdict: TIME LIMIT EXCEEDED

input
500000
617752857 533265574 365848360 ...
view   save

correct output
1999980408
view   save

user output
(no output)
view   save

Test 5

Verdict: TIME LIMIT EXCEEDED

input
500000
209620375 316066031 756114325 ...
view   save

correct output
1999992655
view   save

user output
(no output)
view   save

Test 6

Verdict: ACCEPTED

input
1
1
view   save

correct output
0
view   save

user output
0
view   save

Test 7

Verdict: ACCEPTED

input
2
1 1
view   save

correct output
0
view   save

user output
0
view   save

Test 8

Verdict: ACCEPTED

input
2
2 1
view   save

correct output
0
view   save

user output
0
view   save

Test 9

Verdict: TIME LIMIT EXCEEDED

input
500000
1 1000000000 2 2 2 2 2 2 2 2 2...
view   save

correct output
1999999998
view   save

user output
(no output)
view   save