默认排序
sort(a.begin(), a.end());对数字默认升序;对 pair 默认先比 first,再比 second,也都是升序。
自定义比较器
sort(a.begin(), a.end(), [](auto x, auto y) {
if (x.first != y.first) return x.first > y.first;
return x.second < y.second;
});这表示 first 大的排前面;first 相同,second 小的排前面。
字段多时用 struct
当 pair 的含义不清楚时,用 struct Node { int score, id; }; 会更直观,代码可读性也更好。