Help me in solving CURSED problem

My issue

why cant simple sorting of array work here? can u explain with example where it fails?

My code


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	
	int t;
	cin>>t;
	while(t--){
	    int n;
	    cin>>n;
	    long long arr[n];
	    
	    for(int i=0;i<n;i++){
	        cin>>arr[i];
	    }
	    sort(arr,arr+n);
	    
	    
	    long long sum=arr[0];
	    int cnt=0;
	    for(int i=1;i<n;i++){
	        if(arr[i]<=sum){
	            cnt++;
	        }
	        
	        sum=sum+arr[i];
	    }
	    
	    cout<<cnt<<endl;
	    
	    for(int i=0;i<n;i++){
	        cout<<arr[i]<<" ";
	    }
	    cout<<endl;
	}
	return 0;
}


Problem Link: Cursed Indices Practice Coding Problem - CodeChef

Please help me too

@asmisrivastava
like for ex :-
5
1 2 3 4 11
your code output will be 2
but the correct answer would be 1
1 2 4 11 3