report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Optimal subset - FlandreOJ: Flandre Online Judge

Optimal subset

Time limit: 2000 ms
Memory limit: 256 MB
Given array $b$ of size $m$, sorted array $x$ of size $n$, and array $c$ of size $n$. You need to select a subset of indices $i_1 < i_2 < \dots < i_k$. **Task**: Maximize the cost function: $$Cost = \sum_{j=2}^{k} f(x_{i_j} - x_{i_{j-1}}) + \sum_{j=1}^{k} c_{i_j}$$ where $f(v) = \sum_{p=1}^{m} |v - b_p|$. #### Input - First line: $n, m$ ($n, m \le 10^5$). - Second line: $m$ integers $b_1 \dots b_m$. - Third line: $n$ integers $x_1 \dots x_n$. - Fourth line: $n$ integers $c_1 \dots c_n$. #### Output - Print the maximum cost. #### Example Input: ``` 3 3 1 2 3 1 5 10 10 10 10 ``` Output: ``` 45 ``` #### Subtasks - **Subtask 1 (30 points)**: $n \le 20$. - **Subtask 2 (30 points)**: $n \le 1000$. - **Subtask 3 (40 points)**: No additional constraints.
PTNK Team Selection Test [2025 - 2026]
Balanced subarray
Construct number
Orthogonal pairs
Bubble sort
Optimal subset
Water troughs
Topic
2026
Rating 800
Solution (0) Solution