← 返回 jpmorgan 的题目列表Simplified Asteroid Collision
类型:online_judge
You are given a sequence of moving objects represented by integers:
positive: moving right, negative: moving left
absolute value: size
A collision can happen only when a right-moving object meets a left-moving object to its right. Rules:
smaller one is destroyed
if equal size, both are destroyed
objects moving in the same direction never meet
Return the sequence after all collisions, preserving relative order of survivors.
Input
Line 1: integer n
Line 2: n integers
Output
One line of integers: the remaining sequence (space-separated). Print an empty line if none.
Constraints
1 <= n <= 2*10^5
a[i] != 0, -10^9 <= a[i] <= 10^9
Sample Tests
Input:
5
5 10 -5 -8 20
Output:
5 10 20
Input:
2
8 -8
Output:
Input:
3
10 2 -5
Output:
10
Input:
5
-2 -1 1 2 3
Output:
-2 -1 1 2 3
Input:
6
3 4 5 -10 6 -2
Output:
-10 6
```,
Example
Input
5
5 10 -5 -8 20
Output
5 10 20