#PU567. USACO 2015 December Contest, Bronze — Problem 1. Fence Painting

    ID: 1219 传统题 文件IO:paint 2000ms 256MiB 尝试: 0 已通过: 0 难度: 普及 上传者: 标签>USACO赛事:dec15来源:usaco.orgscoring:equal_test_cases区间DP模拟

USACO 2015 December Contest, Bronze — Problem 1. Fence Painting

USACO 2015 December Contest, Bronze — Problem 1. Fence Painting

题目描述

Several seasons of hot summers and cold winters have taken their toll on Farmer John's fence, and he decides it is time to repaint it, along with the help of his favorite cow, Bessie. Unfortunately, while Bessie is actually remarkably proficient at painting, she is not as good at understanding Farmer John's instructions. If we regard the fence as a one-dimensional number line, Farmer John paints the interval between x=ax=a and x=bx=b. For example, if a=3a=3 and b=5b=5, then Farmer John paints an interval of length 2. Bessie, misunderstanding Farmer John's instructions, paints the interval from x=cx=c to x=dx=d, which may possibly overlap with part or all of Farmer John's interval. Please determine the total length of fence that is now covered with paint.

输入格式

The first line of the input contains the integers aa and bb, separated by a space (a<ba < b). The second line contains integers cc and dd, separated by a space (c<dc < d). The values of aa, bb, cc, and dd all lie in the range 0…1000 \ldots 100, inclusive.

输出格式

Please output a single line containing the total length of the fence covered with paint.

数据范围

(见题面原文)

样例

样例 1

7 10
4 8
6
Here, 6 total units of fence are covered with paint, from $x=4$ all
the way through $x=10$.
Problem credits: Brian Dean