Intermediate question
Description
You have a basket with a capacity of 100 and 30 items for you. The size of each item is known. Q: How many items can be loaded into the basket?
Input Description: A row contains 30 positive integers separated by spaces, indicating the size of each item.
Output Description: a number that indicates the maximum number of items that can be loaded.
Input sample (3 items are used as samples here, and 30 items are actually read): 5 59 100
Output example: 2
Solution: Sort all items by cost-effectiveness, and prioritize cost-effectiveness. In this question, cost-effectiveness is the volume of items.
# Include <algorithm> // Sort Function # Include <iostream> # Include <Vector> Using Namespace STD; Void Main () {Vector < Int > VES ( 3 , 0 ); For ( Int I = 0 ; I < 3 ; I ++ ) CIN > Ves [I]; sort (VES. Begin (), ves. End ()); Int Sum = 0 , Num =0 ; For ( Int I = 0 ; I < 3 ; I ++ ) {Sum + = Ves [I]; If (Sum> 100 ){ Break ;} Num ++ ;} Cout <Num <Endl ;}