[CodeForces] A. Counting Kangaroos is Fun

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.

上一篇:P3605 [USACO17JAN]Promotion Counting P


下一篇:Direct Measure Matching for Crowd Counting