#t102. 逛商场
逛商场
Shopping at the Mall
Problem Description
Xiaoming is a rather unplanned child. No sooner did he get his pocket money than he took it all to the mall.
Xiaoming's rule is simple: whenever he comes across an item he wants to buy, as long as he can afford it, he buys it and only then moves on; if he cannot afford it, he simply skips it.
After a day of shopping, how many items did Xiaoming actually buy?
Input Format
The input consists of lines:
The st line is an integer , the number of items Xiaoming wants to buy in the mall ();
The nd line contains integers, the prices of the items Xiaoming encounters in order;
The rd line is an integer , the amount of pocket money Xiaoming starts with, in yuan.
Output Format
Output line containing one integer: the number of items Xiaoming bought.
Sample Input
6
7 5 9 10 7 4
30
Sample Output
4
Sample Explanation
Xiaoming starts with yuan. The prices he encounters in order are , , , , , .
- He sees the -yuan item, can afford it, and after buying has yuan left;
- He sees the -yuan item, and after buying has yuan left;
- He sees the -yuan item, and after buying has yuan left;
- He sees the -yuan item, but , so he cannot afford it and skips it;
- He sees the -yuan item, and after buying has yuan left;
- He sees the -yuan item, but , so he cannot afford it and skips it.
In the end Xiaoming bought items in total, so the output is .
Constraints
- (item prices)
- is a non-negative integer; its range is not explicitly restricted, but the input is guaranteed to be valid.