#CCBCHBAHAI0000046. Chèn vào mảng tăng đã cho để vẫn tăng (Insert into a Strictly Increasing Array)
Chèn vào mảng tăng đã cho để vẫn tăng (Insert into a Strictly Increasing Array)
Chèn vào mảng tăng đã cho để vẫn tăng (Insert into a Strictly Increasing Array)
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem
Given a strictly increasing integer array
and an integer that is different from every array element.
Insert so that the resulting array has elements and is still strictly increasing.
Define
$$p=\min\left(\{i\mid 0\le i<n,\ a_i>x\}\cup\{n\}\right).$$Then must be inserted at index , while old elements from onward move one position to the right.
Print the new size and the resulting array.
Input
The first line contains integers and . The second line contains strictly increasing integers .
Output
Print on the first line. Print the array after inserting on the second line.
Subtask
Subtask 1 (100 points): ; ; ; for every .
Example
Input
5 6
1 3 5 8 10
Output
6
1 3 5 6 8 10
Explanation
The first element greater than is at index , so . Inserting before keeps the array strictly increasing.