getting segmentation fault with set : <p>What is wrong with my code. I am getting segmentation fault on submission.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;set&gt;
#include &lt;algorithm&gt;
using namespace std;

int main() {
    int t;
    cin&gt;&gt;t;
    while(t--){
        int n,k;
        cin&gt;&gt;n&gt;&gt;k;
        int x;
        set&lt;int&gt; s;
        for(int i=0;i&lt;n;i++){
            cin&gt;&gt;x;
            s.insert(x);
        }
        int m;
        int ans=0;
        for(int i=0;i&lt;k;i++){
            m=*s.rbegin();
            ans+=m;
            s.insert(m/2);
            s.erase(m);

        }
        cout&lt;&lt;ans&lt;&lt;"\n";
    }
    return 0;
}
</code></pre>

<p>Constraints for the problem are:</p>

<p>1 ≤ T ≤ 10</p>

<p>1 ≤ N ≤ 10^5</p>

<p>0 ≤ K ≤ 10^5</p>

<p>0 ≤ Si ≤10^5 </p>
