title: Inserting and removing elements from an array while maintaining the array to be sorted
body: <p>I'm wondering whether somebody can help me with this problem. I'm using C/C++ to program and I need to do the following:</p>
  
  <p>I am given a sorted array P (biggest first) containing floats. It usually has a very big size.. sometimes holding correlation values from 10 megapixel images. I need to iterate through the array until it is empty. Within the loop there is additional processing taking place. </p>
  
  <p>The gist of the problem is that at the start of the loop, I need to remove the elements with the maximum value from the array, check certain conditions and if they hold, then I need to reinsert the elements into the array but after decreasing their value. However, I want the array to be efficiently sorted after the reinsertion.</p>
  
  <p>Can somebody point me towards a way of doing this? I have tried the naive approach of re-sorting everytime I insert, but that seems really wasteful. </p>