Please one more test Case to better understand this problem.
Give one more test case with n >5 and <10
Lets discuss the given one only
Here we have 1 test case.
There are 2 stations
Fuel needed to go to first station = 1 units. Cost of fuel for that is 5 per litre. So you buy 1 unit. (Ans+=5)
Now for next station, fuel required = 2 units and cost is 1 per litre. So you buy 2 units (Ans+=2)
PS: had the cost at first station been lesser, we would have bought it for next station as well.
JAHA SASTA,WAHA SE UTNA BHARWA LO JITNA POSSIBLE.
Lets now take a new example
1
5
3 1 6 2 3 (Cost)
2 1 5 3 6 (Fuel Required)
Here we buy 3x2 + 1x(1+5+3+6) + 0 + 0 + 0 from respective stations.
Ans = 21
#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+=tempdtemp2;
temp=pet[i];
dtemp2=0;
}
dtemp2+=dist[i];
}
cout<<res+dtemp2*temp<<endl;
}
}
what is wrong in this code.