I'm not sure of an "Efficient" way of sorting a vector, or array, in the manner you'd like (i.e. 1,2,3,4,1,2,3,4,1,2,4,4). But for an exhaustive way you could...
Iterate through the unsorted vector (UV) and find the minimum value above the previous runs minimum value (initialize with zero for first round and each time there is no value above the searched value). When a minimum value is found record its index and after iterating through the vector remove the value at the stored index and add this value to the sorted vector (SV). Continue to iterate through the UV until it is empty, and each item has been added to the SV. Now iterate through the SV and add 1 each time the preceding value is less than the current value.
- Init prev-min value. and current-min, also storing its index each time its updated.
- Loop over the UV (unsorted vector).
- If a value is above prev-min but below current-min set as new current-min, and update the current min index.
- At the end of the vector loop you have your current-min and its index value.
- If the prev-min was the same as the current-min then set the prev-min back to zero and loop again (step 2).
- Add the current lowest value to the SV and remove the current-min from the UV.
- Set the prev-min as the current-min and repeat the loop (step 2).
- Once the UV is empty iterate through the SV.
- each time the current value is above the previous value add one to count.
This should produce the sorted vector with each consecutive value higher than the previous unless it was the highest, in which case the next lowest value is used.