[CodeForces] A. Counting Kangaroos is Fun

 

There can be only at most N / 2 hold and held pairs based the problem's statment. So a greedy approach is just to divide A into smaller and bigger groups, then try to match two groups greedily.

 

1. Sort A;

2. from A[0] to A[n / 2 - 1], find the smallest unused number from the bigger group. Each sucessful match contributes 1 to ans while all the unmatched numbers contribute 1 individually to ans.

posted @ 2022-01-24 12:52  Review->Improve  阅读(82)  评论(0编辑  收藏  举报