# HackerEarth Jiva, The Self Driven Car problem solution

In this HackerEarth Jiva, The Self Driven Car problem solution Jiva is a self-driven car and is out on its very first drive. It aims to earn some revenue by serving as a taxi driver. It starts its journey from a point and travels in a line for 100 Km. It picks and drops passengers on the way, but can accommodate a maximum of M passengers at once.

Jiva wants to be very economical & intends to equally split the fare among the number of passengers as the following: - The normal rate being - 10 INR/Km for every passenger - If there are 2 passengers in the car at any part of the journey, it gives a 5% discount to both the passengers for that part of the journey. - If there are 3 or more passengers in the car at any part of the journey, it gives a 7% discount to all of them for that part of the journey.
Also note that if the cab was full at any point in the journey, Jiva can not take any more passengers at that time and reports "Cab was full" to its engineers in the end.
we have Given, a total of N passengers that board Jiva at different points. Find the total revenue earned after the journey completes.

## HackerEarth Jiva, The Self Driven Car problem solution.

`#include<bits/stdc++.h>using namespace std;#define rep(i,n) for(i=0;i<n;i++)#define ll long long#define elif else if#define pii pair<int,int>#define mp make_pair#define pb push_back#define CLEAR(array, value) memset(ptr, value, sizeof(array));#define si(a)     scanf("%d", &a)#define sl(a)     scanf("%lld", &a)#define pi(a)     printf("%d", a)#define pl(a)     printf("%lld", a)#define pn        printf("\n")#define SZ(x)  (int)((x).size())#define N 2000000int main(){   freopen("in.txt","r",stdin);   freopen("out","w",stdout);   int t;   cin>>t;   assert(1<=t && t<=10);   while(t--)   {     int i,j,n,m,f=0;     double ans=0;     cin>>n>>m;     assert(0<=n && n<=1000);     assert(1<=m && m<=1000);     vector<pii>vp(n);     double p=0;     rep(i,n)     {      cin>>vp[i].first>>vp[i].second;      assert(0<=vp[i].first && vp[i].first<=99);      assert(vp[i].first<=vp[i].second && vp[i].second<=100);      }      vector<int>cab;      for(i=0;i<=100;i++)      {       // cout<<i<<" "<<cab.size();        for(j=0;j<cab.size();j++)        {          if(i==vp[cab[j]].second){            cab.erase(cab.begin()+j);            j--;          }        }        for(j=0;j<n;j++)        {          if(cab.size()==m)break;          if(vp[j].first==i && cab.size()<m)            cab.push_back(j);        }        p=cab.size();       // cout<<"  "<<cab.size()<<"\n";        if(p==m)          {            f=1;            //continue;          }        if(p==2)          ans+= 9.5*p;        else if(p>=3)          ans+= 9.3*p;        else          ans+=10.0*p;      }      cout<<(int)(ans+0.5);      if(f)        cout<<" Cab was full";      if(t>0)        cout<<"\n";   }  return 0;}`

### Second solution

`#include<bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(i= a ; i < b ; ++i)#define rep(i,n) FOR(i,0,n)#define INF INT_MAX#define pb push_back#define mp make_pair#define fill(x,v) memset(x,v,sizeof(x))#define si(n) scanf("%d",&n)#define sd(n) scanf("%lf",&n)#define F first#define S second#define mod (ll)(1e9 + 7)#define ll long long int#define MAX 1000006ll modpow(ll a,ll n,ll temp){ll res=1,y=a;while(n>0){if(n&1)res=(res*y)%temp;y=(y*y)%temp;n/=2;}return res%temp;} vector<int> car;vector<pair<int,int> > timeit;int main(){  int t,i,j,sz,n,m,fin,flag,v1,v2;  double calc, cnt, ans;  si(t);  assert(t>=1 && t<=10);  while(t--)  {    flag=0; ans=0;    car.clear(); timeit.clear();    si(n); si(m);    assert(n>=0 && n<=1000);    assert(m>=0 && m<=1000);    rep(i,n)    {      si(v1); si(v2);      assert(v1>=0 && v1<=100);      assert(v2>=0 && v2<=100);      timeit.pb(mp(v1,v2));      timeit[i]=mp(v1, v2);    }    rep(i,101)    {      sz=car.size();      rep(j,car.size())      {        if(i==timeit[car[j]].S)        {          car.erase(car.begin()+j);          j--;        }      }      rep(j,n)      {        sz=car.size();        if(sz==m)          break;        if(timeit[j].F==i && sz<m)          car.pb(j);      }      calc=car.size();      if(calc==m)        flag=1;      if(calc==2)        ans += 9.5*calc;      else if(calc>=3)        ans += 9.3*calc;      else        ans += 10.0*calc;    }    cout<<(int)(ans+0.5);    if(flag)      cout<<" Cab was full";    cout<<endl;  }  return 0;}`