Prefer const iterators and use more <algorithm>.