Mooo Moo
Time limit1sMemory limit128 MB
Find the fewest cows whose breed volumes explain the recorded volumes when each field spills its total minus one into the next field.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Farmer John forgot how many cows he owns. He placed microphones in fields along a road to estimate cow counts from mooing volume.
Breed moos at volume . Wind blows left to right: if a field's total volume is , the next field gains from carryover.
Given recorded total volumes, find the minimum possible number of cows, or if impossible.
Input
Line 1: , .
Next lines: .
Next lines: recorded volume in each field.
Output
Minimum number of cows, or .