PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000074. Sinh nhật Sage (bản khó) (Sage’s Birthday (Hard Version))
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Sinh nhật Sage (bản khó) (Sage’s Birthday (Hard Version))
Sage’s Birthday (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Rearrange prices (duplicates allowed) to maximize the number of internal elements strictly smaller than both neighbors. Output both the optimal number and one optimal rearrangement.
Input
Line 1: . Line 2: prices.
Output
Line 1: optimal count. Line 2: any permutation of the given multiset realizing that count.
Subtasks
- Subtask 1 (20 points): Exactly one dataset; ; ; equal prices are allowed.
- Subtask 2 (30 points): Exactly one dataset; ; ; equal prices are allowed.
- Subtask 3 (50 points): Exactly one dataset; ; ; equal prices are allowed.
Example
Input
7
1 3 2 2 4 5 4
Output
3
3 1 4 2 4 2 5
Explanation
The displayed order has three strict local minima at positions 2, 4, and 6; no order of seven elements can have more.