Monday, May 15, 2017

11389 - The Bus Driver Problem uva problem



problem linkk:

Discussion : in this problem we just have to sort the evening and morning hours. then add with smallest one with greatest one then compare it with d.  if it exceed then multiple with over time rate


#include<bits/stdc++.h>
using namespace std;
int main()
{


      int n,d,r,i,j,m,total,sum;
      vector<int> evening;
      vector<int>morining;
      while(scanf("%d %d %d",&n,&d,&r)==3)
      {
      morining.clear();
      evening.clear();
      if(n==0&&d==0&&r==0)
      break;
      sum=0;
            for(i=0;i<n;i++)
            {
               cin >>m;
               morining.push_back(m);
            }
            for(i=0;i<n;i++)
            {

               cin >>m;
               evening.push_back(m);

            }
            sort(morining.begin(),morining.end());
            sort(evening.begin(),evening.end());
            for(i=0;i<n;i++)
            {
            total=morining[i]+evening[n-i-1];
              if(total>d)
              {
              sum+=(total-d)*r;


              }


            }

                 printf("%d\n",sum);

      }
      return 0;


}

No comments:

Post a Comment