// Return the item indices and total value using greedy method
// Put the most valuable item in the knapsack if possible.
Return the item indices and total value using greedy method
Put the most valuable item in the knapsack if possible.
// Return the item indices and total value using greedy method // Put the most valuable item in the knapsack if possible .
func greedy(ws []int, vs []int, c int) (items []int, value int) {
	sort.Sort(sort.Reverse(byValue{ws: ws, vs: vs}))
	fmt.Println("ws", ws, "vs", vs)
	value = 0
	for i, v := range vs {
		if ws[i] <= c {
			c -= ws[i]
			items = append(items, ws[i])
			value += v
		}
	}
	return items, value
}
func greedy ( ws [ ] int , vs [ ] int , c int ) ( items [ ] int , value int ) { sort . Sort ( sort . Reverse ( byValue { ws : ws , vs : vs } ) ) fmt . Println ( " " , ws , " " , vs ) value = 0 for i , v := range vs { if ws [ i ] <= c { c -= ws [ i ] items = append ( items , ws [ i ] ) value += v } } return items , value }
Return the item indices and total value using greedy method
Put the most valuable item in the knapsack if possible.
Return the item indices and total value using greedy method Put the most valuable item in the knapsack if possible .