Help me in solving ONEFROMK problem

My issue

i am using the same logic then why’s that my code is having wrong answer for the other test cases

My code

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

int main(){
    
 
        int t;
        cin>>t;
        while(t--){
            
            int n;
            int sum=0;
            cin>>n;
            int arr[n];
            for(int i=0;i<n;i++){
                cin>>arr[i];
                sum+=arr[i];
            }
            sort(arr,arr+n);
            for(int i=0;i<n;i++){
                cout<<sum<<" ";
                sum-=arr[i];
            }
            cout<<endl;
        }
    
}

Problem Link: ONEFROMK Problem - CodeChef

@code_shaaban
use long long int