PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000052. Hai dãy tam phân (Ternary Sequence)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hai dãy tam phân (Ternary Sequence)
Ternary Sequence
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Two equal-length sequences contain only 0, 1, 2, with frequency triples and . Rearrange both freely. Define if , if equal, and if . Maximize .
Input
Line 1: . Line 2: .
Output
Print the maximum sum.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
2 3 2
3 3 1
Output
4
Explanation
Two 2s in can be matched with two 1s in , each contributing +2. Remaining elements can be paired without negative contributions, giving the maximum 4.