PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000044. Đốt trại liên hoàn (Burn the Linked Camp)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đốt trại liên hoàn (Burn the Linked Camp)
Burn the Linked Camp
Source: ZOJ
Version: Phuoc Hung OJ Extended
Problem Statement
There are successive camps. Camp contains an integer number of soldiers from to . Each observation requires at least soldiers in camps through . Find the minimum total, or output Bad Estimations if contradictory.
Input
First line , then capacities , then triples .
Output
Print the minimum total soldiers, or exactly Bad Estimations.
Subtasks
- Subtask 1 (20 points): , ; ; ; .
- Subtask 2 (30 points): , ; ; ; .
- Subtask 3 (50 points): , ; ; ; .
Examples
Input
3 2
1000 2000 1000
1 2 1100
2 3 1300
Output
1300
Explanation
The constraints require and , so the total is at least . The allocation stays within capacities and meets both observations. Hence the optimum is .