updata the greedy function