#PU1497. USACO 2025 February Contest, Gold — Problem 1. Bessie's Function
USACO 2025 February Contest, Gold — Problem 1. Bessie's Function
USACO 2025 February Contest, Gold — Problem 1. Bessie's Function
题目描述
Bessie has a special function that takes as input an integer in and returns an integer in (). Her function is defined by integers where (). Bessie wants this function to be idempotent. In other words, it should satisfy for all integers . For a cost of , Bessie can change the value of to any integer in (). Determine the minimum total cost Bessie needs to make idempotent.
输入格式
The first line contains . The second line contains space-separated integers . The third line contains space-separated integers .
输出格式
(见题面原文)
数据范围
Subtasks:
样例
样例 1
5
2 4 4 5 3
1 1 1 1 1
3
We can change $a_1 = 4$, $a_4 = 4$, $a_5 = 4$. Since all $c_i$ equal one, the
total cost is equal to $3$, the number of changes. It can be shown that there is
no solution with only $2$ or fewer changes.
样例 2
8
1 2 5 5 3 3 4 4
9 9 2 5 9 9 9 9
7
We change $a_3 = 3$ and $a_4 = 4$. The total cost is $2+5=7$.