n = int(input())
h = list(map(int, input().split()))
w = list(map(int, input().split()))
sussies = [list(i) for i in zip(h,w)]
stack = []
def rect(a,b):
return a*(a+1)*b*(b+1)//4
def comb():
if len(stack)>1 and stack[-1][0] == stack[-2][0]:
a = stack.pop()[1]
stack[-1][1] += a
ans = 0
for i in sussies:
if not stack:
stack.append(i)
else:
while stack[-1][0] > i[0]:
if len(stack)==1:
ans += rect(stack[-1][0],stack[-1][1])-rect(i[0],stack[-1][1])
stack[-1][0] = i[0]
else:
sus = max(stack[-2][0], i[0])
ans += rect(stack[-1][0],stack[-1][1])-rect(sus,stack[-1][1])
stack[-1][0] = sus
comb()
stack.append(i)
comb()
while len(stack) != 1:
sus = stack[-2][0]
ans += rect(stack[-1][0],stack[-1][1])-rect(sus,stack[-1][1])
stack[-1][0] = sus
comb()
ans += rect(stack[0][0], stack[0][1])
print(ans)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
18220 KB |
Output is correct |
2 |
Incorrect |
50 ms |
19328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
18220 KB |
Output is correct |
2 |
Correct |
35 ms |
18224 KB |
Output is correct |
3 |
Correct |
35 ms |
18252 KB |
Output is correct |
4 |
Correct |
36 ms |
18228 KB |
Output is correct |
5 |
Correct |
34 ms |
18160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
18312 KB |
Output is correct |
2 |
Incorrect |
42 ms |
19096 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
18988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
18140 KB |
Output is correct |
2 |
Incorrect |
46 ms |
19020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
18224 KB |
Output is correct |
2 |
Incorrect |
46 ms |
19292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
18220 KB |
Output is correct |
2 |
Incorrect |
50 ms |
19328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |