Advertisement
Waliullah8328

Gredy KS or Fractional K

Jul 25th, 2021
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. //Gredy KS  or Fractional KS
  3. int main() {
  4.     int KS = 10;
  5.     int wights[4] = {2, 3, 3, 4};
  6.     int unit_price[4]= {15, 18, 20, 30};
  7.    
  8.     int profit = 0;
  9.    
  10.     for(int i = 3; i >= 0; i--)
  11.     {
  12.         if(KS > wights[i])
  13.         {
  14.             profit = profit + (wights[i] * unit_price[i]);
  15.             KS = KS - wights[i];
  16.         }
  17.         else
  18.         {
  19.             profit = profit + (KS * unit_price[i]);
  20.             KS = 0;
  21.             break;
  22.         }
  23.     }
  24.    
  25.     printf("Max Profit = %d\n",profit);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement