#C7255. Minimum Cuts to Match Tree Heights

    ID: 51106 Type: Default 1000ms 256MiB

Minimum Cuts to Match Tree Heights

Minimum Cuts to Match Tree Heights

In this problem, you are given two arrays representing the current heights and the target heights of trees in a forest. Your task is to determine the minimum number of cuts needed to transform the current configuration into the target configuration. Each cut operation reduces the height of a tree by exactly 1 unit.

Formally, let \(H = [h_1, h_2, \dots, h_n]\) be the current heights and \(T = [t_1, t_2, \dots, t_n]\) be the target heights. The goal is to compute the sum of \(h_i - t_i\) for all \(i\) such that \(h_i > t_i\). If a tree's current height is less than or equal to its target height, no cuts are needed for that tree.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a single integer \(n\) representing the number of trees.
  • The second line contains \(n\) space-separated integers indicating the current heights of the trees.
  • The third line contains \(n\) space-separated integers indicating the target heights of the trees.

outputFormat

Output a single integer to stdout which represents the minimum total number of cuts required to achieve the target tree heights.

## sample
3
3 4 5
1 2 4
5

</p>