Help me in solving BIT2A problem

My issue

Why it show Runtime Error ?

My code

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

int main() {
	// your code goes here
	int t;
	std::cin >> t;
	while(t--)
	{
	    int n;
	    std::cin >> n;
	    int *a=new int[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    sort(a, a+n);
	    vector<int>v;
	    for(int i=0;i<n-1;i++)
	    {
	        if(a[i]<a[i+1])
	        {
	            v.push_back(n-i-1);
	        }
	        else
	        v.push_back(0);
	    }
	    for(int i=0;i<n;i++)
	    {
	        cout<<v[i]<< " ";
	    }
	    cout<<endl;
	}
	return 0;
}

Problem Link: BIT2A Problem - CodeChef

@pranto1610
Although I do not know C++ that well but I would suggest removing sort and then trying again because in the question the elements provided have already been sorted.

Here is my code in Python

# cook your dish here
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for j in range((n)-1):
        c=0
        for i in range(j,n):
            if(a[i]>a[j]):
                c+=1
        b.append(c)
    b.append(0)
    for i in b:
        print(i,end=" ")
    print('')
        
1 Like