I want to solve greedy problem job sequence but before that i want to reolve this runtime error i want to sort the array of structures according to my dl (deadline) structure variable

    #include<iostream>

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

struct gold
{
int job_id;
int deadline;
int p;
};
bool cmp(gold a,gold b)
{
return a.p>b.p;
}
int main()
{
gold A[101];
//code
int t;
cin>>t;

  int N;
  cin>>N;
  for(int i=0; i<N; i++)
  {
    cin>>A[i].job_id;
    cin>>A[i].dl;
    cin>>A[i].p;
   }
  for(int i=0; i<=N-1; i++)
  {
    sort(A,A+N,cmp);
  }
  for(int i=0; i<N; i++)
  {
      cout<<A[i].job_id<<" "<<A[i].dl<<" "<<A[i].p<<endl;
  }
return 0;

}

Hey @AyushKumar9032
If you want to sort your array of structures according to the deadlines, you’ve to use the dl variable in the comparator instead of p.
Also you need to write the sort function only once and not run a loop for that.
Also you need to run a loop after taking input t, because you’ve to follow the same procedure for all test cases. The code after changes will be

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

struct gold
{
int job_id;
int deadline;
int p;
};
bool cmp(gold a,gold b)
{
return a.p>b.p;
}
int main()
{

//code
int t;
cin>>t;
while(t–){
int N;
cin>>N;
gold A[101];
for(int i=0; i<N; i++)
{
cin>>A[i].job_id;
cin>>A[i].dl;
cin>>A[i].p;
}

sort(A,A+N,cmp);

for(int i=0; i<N; i++)
{
cout<<A[i].job_id<<" “<<A[i].dl<<” "<<A[i].p<<endl;
}
}
return 0;
}