Vote-Value Disparity 1
Time limit1sMemory limit128 MB
Partition N connected provinces into K connected districts to minimize the ratio between the most and least powerful single vote.
- Level
Hard8 of 10
- Topics
- Graph, Binary search, DFS
- Solved
- No attempts yet
Problem
A national election will be held in the JOI kingdom. The kingdom has provinces.
The map is an grid. Each cell connects to neighbors by sharing a side. The grid is partitioned into connected provinces. Province has voters.
You must divide the provinces into electoral districts to elect representatives. Each district contains at least one province, and the cells in a district form a connected region. Cells connect only through shared sides, not shared corners.
The weight of a single vote in a district is . The vote-value disparity is the maximum such weight divided by the minimum. Minimize this disparity.
Input
The first line contains , , , and .
Each of the next lines has integers , the province id of each cell.
Each of the next lines has , the number of voters in province .
Output
Print lines. Line is the district number ( to ) for province .
Constraints
- Each province forms a connected region on the grid.