Hungry Cow
InterviewTime limit2sMemory limit1024 MB
Given haybale deliveries on specific days, count how many haybales Bessie eats in the first T days, eating one per day when stock is on hand.
- Level
Easy3 of 10
- Topics
- Greedy, Simulation
- Solved
- No attempts yet
Problem
Bessie is a hungry cow. Each day, at dinner, she eats one haybale if there is one in the barn. Farmer John does not want Bessie to starve, so on some days he sends a delivery of haybales. Deliveries arrive in the morning, before dinner. Specifically, on day Farmer John sends a delivery of haybales (, ).
Compute the total number of haybales Bessie will eat during the first days.
Input
The first line contains and (, ). Each of the next lines contains and . It is additionally guaranteed that .
Output
Output the number of haybales Bessie will eat during the first days.
The large integers involved in this problem may require 64-bit integer types (for example, long long in C/C++).