Thirteen problems that sort solves almost on its own. Mind the sizes: several
go up to 2·10⁶ numbers, so keep the fast-IO lines, read into a vector<long long>
where the values reach 10¹⁸, and print with "\n" or ' ', never endl.
- Increasing Order and Decreasing Order:
sort, andsortwithgreater<long long>(). - Alphabetize: a string of up to 5·10⁶ letters — sort the string itself.
- Median and The k-th Smallest: sort, then one index. Work the index out on the sample before you type it.
- Sort Substrings: cut out
s.substr(l - 1, r - l + 1), sort the piece, print it. The total length of all pieces is bounded, so this is fast enough. - Merge Two Sorted Lists: putting everything in one vector and sorting it gives the right sequence; the "first array first" rule only matters for equal values, which look the same when printed.
- Sorted Indices and Sort and Remember: the line-up trick — pairs
{value, index}. - Lexicographic Points: pairs
{x, y}and plainsort. Order by Height wants y first: read each point into{y, x}and print it back asx y. - Race Standings and Рейтинг участников: the larger value first.
{-distance, id}withsort, or{score, name}pairs sorted withgreater<pair<int, string>>()(names are not compared when scores are distinct — and here they are).