Tell me where i am wrong

this is my code link
or my code is : Please Reply
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
long int res=0;
vector dist;
vector pet;
int n;
cin>>n;
int temp=0;
for(int i=0;i<n;i++){
cin>>temp;
pet.push_back(temp);
}
for(int i=0;i<n;i++){
cin>>temp;
dist.push_back(temp);
}
res+=pet[0]dist[0];
temp=pet[0];
int dtemp2=0;
for(int i=1;i<n;i++){
if(temp>pet[i]){
res+=temp
dtemp2;
temp=pet[i];
dtemp2=0;
}
dtemp2+=dist[i];
}
cout<<res+dtemp2*temp<<endl;
}
}

Your approach is not fine. This is what we need to do:

We just need to buy petrol from the minimum possible rates checkpoints. Lets say we are at checkpoint X. Now there are X+1 checkpoints up to this checkpoint. We can easily see that for buying petrol for going to checkpoint X+1 , we just need to find the minimum possible C[i] where i can be from 1 to X+1 . Thus, we can just compare the minimum petrol rate till now(lets say denote it by (mi) at each of the checkpoint with the checkpoint rate i.e. C[i] . Now two possible cases arise:

First Case: mi <= C[i], No need to update mi i.e. petrol for this checkpoint has to be bought with the rate .

Second Case: mi > C[i] , We need to update mi and petrol for this checkpoint has to be bought with the new rate i.e. C[i] .

After iterating through all checkpoints following the above algorithm will lead to minimum travel cost.

In easy words, JAAHA PETROL SASTA MILE, WAHA SE LO SARA, ELSE JITNA ZROORI, UTNA HII.

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.