#GD0000178. Đặt quân trên bàn cờ (Chips on the Board)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đặt quân trên bàn cờ (Chips on the Board)
Chips on the Board
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an board and two arrays of positive integers and . You may place chips into distinct cells. Placing a chip in row , column costs .
For every cell , there must be at least one chip in row or in column . A chip directly at also counts. Not every cell needs to contain a chip.
Find the minimum total cost of a placement satisfying the condition.
Input
Line 1 contains integer , the number of rows and columns.
Line 2 contains exactly integers , the row cost components.
Line 3 contains exactly integers , the column cost components.
Output
Print one integer: the minimum total cost of any valid chip placement.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
3
1 4 1
3 2 2
Output
10
Explanation
There are rows and columns. Place chips at , and . Their costs are , , and , totaling . Every column then has a chip, so all cells are covered. Placing one chip in each row in the cheapest column would cost . The minimum is therefore .