PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000131. Băng dính sửa thanh gỗ (Tape)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Băng dính sửa thanh gỗ (Tape)
Tape
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A stick consists of unit segments, with broken positions given in strictly increasing order. Use at most contiguous integer-length tape pieces to cover all broken segments, possibly covering intact segments too. Minimize the total tape length.
Input
The first line contains . The next line contains positions .
Output
Print the minimum total length of tape.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
4 100 2
20 30 75 80
Output
17
Explanation
A tape piece of length covers positions and ; another of length covers and . Total .