gready algorithm