Advertisement
Pabon_SEC

The Bus Driver Problem

May 13th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int morning[103],evening[103];
  6.  
  7. int main()
  8. {
  9.     int n,d,r,i,j,sum,tot;
  10.  
  11.     while(scanf("%d%d%d",&n,&d,&r)==3)
  12.     {
  13.         if(!n && !d && !r)
  14.             break;
  15.  
  16.         for(i=1; i<=n; i++)
  17.         {
  18.             scanf("%d",&morning[i]);
  19.         }
  20.  
  21.         sort(morning+1,morning+n+1);
  22.  
  23.         for(i=1; i<=n; i++)
  24.         {
  25.             scanf("%d",&evening[i]);
  26.         }
  27.  
  28.         sort(evening+1,evening+n+1);
  29.  
  30.         tot = 0;
  31.  
  32.         for(i=1,j=n; i<=n; i++,j--)
  33.         {
  34.             sum=morning[i]+evening[j];
  35.  
  36.             if(sum>d)
  37.             {
  38.                 tot += sum - d;
  39.             }
  40.         }
  41.  
  42.         printf("%d\n",tot*r);
  43.  
  44.     }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement