cswork / OA打开练习工作台

AmazonOA #79

Count Bought Items (Recurring Shop Purchase)

估计困难可在线判题

考点(AI 标注)位运算二分查找模拟/实现

Buy the n items cyclically in order. The t-th purchase of item i costs t×cost[i]. The problem text does not say what happens when an item is unaffordable; the Python, Java, and C++ solutions of the same fixed OAMaster version all stop immediately at the first unaffordable item, so this site specifies that purchasing stops rather than skipping and continuing.

输入格式

The first line contains n m; the second line contains n integers cost[i]. 1≤n≤100000, 1≤m≤10^15, 1≤cost[i]≤200000.

输出格式

Output the total number of items bought before stopping. Stop immediately when the current item is unaffordable; do not skip it.

样例 1

输入:

2 2
5 1

输出:

0

样例 2

输入:

2 5
2 1

输出:

2

样例 3

输入:

2 12
1 2

输出:

5

样例说明

First binary search the number of complete rounds that can be bought, then process the next round in order; stop at the first unaffordable item.