Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //Gredy KS or Fractional KS
- int main() {
- int KS = 10;
- int wights[4] = {2, 3, 3, 4};
- int unit_price[4]= {15, 18, 20, 30};
- int profit = 0;
- for(int i = 3; i >= 0; i--)
- {
- if(KS > wights[i])
- {
- profit = profit + (wights[i] * unit_price[i]);
- KS = KS - wights[i];
- }
- else
- {
- profit = profit + (KS * unit_price[i]);
- KS = 0;
- break;
- }
- }
- printf("Max Profit = %d\n",profit);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement