Wrong answer for the test cases

#include
#include<bits/stdc++.h>
using namespace std;
bool compare(pair<int,int>a,pair<int,int>b)
{
return a.first<b.first;
}
int main() {
int t;
cin>>t;
int n;
while(t–)
{

	cin>>n;

	pair<int,int> c[n];
	int l[n];
	int c1;
	int cost=0;
	for(int i=0;i<n;i++)
	{
     cin>>c[i].first;
	 if(i==0)
	 {
		 c1=c[0].first;
	 }
	 c[i].second=i;
	}
	sort(c,c+n,compare);
	
	for(int i=0;i<n;i++)
	{
		cin>>l[i];
	
	}
	int j=n-1;
	int m=0;
	int st;
	while(j!=0 && j>0)
	{
		 st=c[m].second;//to find index
		// cout<<st<<" ";
		
		int sum=0;
		for(int i=j;i>=st;i--)
		{
			sum=sum+l[i];
			// cout<<l[i]<<" ";

		}
		// cout<<sum<<" ";
		j=st-1;
		cost=sum*(c[m].first)+cost;
		m++;
//  cout<<cost;
	}
	if(st!=0)
	{

cost=cost+(c1*l[0]);
}

cout<<cost<<endl;
	
}
return 0;

}

please provide code using ide link…

please check the recent code

#include #include<bits/stdc++.h> using namespace std; bool compare(pair<int,int>a,pair< int,int>b) { return a.first<b.first; } int main() { int t; cin>>t; int n; while(t–) { cin>>n; pair<int,int> c[n]; int l[n]; int c1; int cost=0; for(int i=0;i<n;i++) { cin>>c[i].first; if(i==0) { c1=c[0].first; } c[i].second=i; } sort(c,c+n,compare); for(int i=0;i<n;i++) { cin>>l[i]; } int j=n-1; int m=0; int st; while( j>=0) { if(m==0) st=c[m].second;//to find index else { int k=c[m].second; if(st<k) { m++; continue; } else { st=k; } } int sum=0; for(int i=j;i>=st;i–) { sum=sum+l[i]; } j=st-1; cost=sum*(c[m].first)+cost; m++; } // if(st!=0) // cost=cost+(c1*l[0]); cout<<cost<<endl; } return 0; }

i asked you to please provide code using ide link… is not possible to read code you code if you paste it here as a text…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.