report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Positive and negative - MarisaOJ: Marisa Online Judge

Positive and negative

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ with $n$ integer elements, arrange the array by interleaving the negative and positive elements. The relative order of elements with the same sign should not be changed. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. ### Output - Print the array $A$ after rearranging the elements in an interleaved manner. ### Constraints - $1 \le n \le 1000$. - $-1000 \le A_i \le 1000$. - $A_i \neq 0$. ### Example Input: ``` 6 1 5 -3 6 2 -5 ``` Output: ``` -3 1 -5 5 6 2 ``` In this example, the elements are arranged by interleaving negative and positive elements. When there are no more negative elements, continue using the remaining positive elements.
Array
Even elements
Smallest value
Average
Array reversal
Negative and positive
Consecutive differences
Largest value
Positive and negative
Dominant element
Second largest
Maximum product
Array rotation
Palindrome array
Circle
Insert
Positive subarray
Sorting
Similar Arrays
Unique
Unique 2
Frequent value
Most Frequent Value
Bitonic sequence
Swap
Topic
Basic
Rating 800
Solution (0) Solution