Ordena un Vector R S98018


Statement
 

pdf   zip   main.cc

A vector R is a vector that is composed of two parts:

v=x1x2x3x4xny1y2y3ymv = x_1 ~ x_2 ~ x_3 ~ x_4 \dots x_n ~ y_1 ~ y_2~ y_3 \dots y_m

such that the part x1xnx_1 \dots x_n and the part y1ymy_1 \dots y_m are ordered strictly in increasing order but ym<x1y_m < x_1. Furthermore, we have that n,m>0n,m > 0. That is, neither part is empty.

We need to implement the function void ordena(vector<int>& v, int pos) with the following specification:

PRE: vv is a vector R such that v3\mid \! v \! \mid \geq 3, and pospos is the position of y1y_1 in vv.

POST: The vector vv is sorted.

Observation

You only need to send the function we ask for and the actions and functions that you define yourself. The rest will be ignored.

You cannot use the operation sort from the stl library.

Hint: knowing the position of y1y_1 can help you sort the vector in linear time.

On the other hand, if you use an auxiliary vector to sort you will have a penalty of 5-5 on manual correction even if you have a green traffic light.

Input

An undetermined number of vectors R with the following format: an integer indicating their size, then the vector R and finally the position where y1y_1 is located. Every vector R has a size greater than or equal to 3.

Output

The sorted vector vv.

Sample session
ENTRADA 1:
15
11 12 13 14 15 1 2 3 4 5 6 7 8 9 10
5

SORTIDA 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



ENTRADA 2:
15
3 4 5 6 7 8 9 10 11 12 13 14 15 1 2
13

SORTIDA 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



ENTRADA 3:
15
15 1 2 3 4 5 6 7 8 9 10 11 12 13 14
1

SORTIDA 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



ENTRADA 4:
5
12 15 4 7 8
2

SORTIDA 4:
4 7 8 12 15
Information
Author
PRO1
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
C++
User solutions
C++