| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 0.5 초 | 1024 MB | 31 | 16 | 15 | 83.333% |
Spring has arrived, ushering in a season of hard work at the Swarm of Bees Company (SBC). With the blooming of N beautiful flowers in the garden, each flower boasts a certain quantity of pollen grains. The SBC enforces strict rules to keep the bees industrious in their pollen collection.
Gertrude finds these rules bewildering and seeks help to determine the pollen amount she must collect when it’s her turn. Getrude has amazingly sharp sight and noticed that she is currently the K-th bee in the SBC-defined order.
The first line contains two integers N (1 ≤ N ≤ 106) and K (1 ≤ K ≤ 109), representing the number of flowers and Gertrude’s position in the bee line, respectively. The second line contains N integers, where the i-th integer Fi (1 ≤ Fi ≤ 106 for 1 ≤ i ≤ N) denotes the initial quantity of pollen grains of the i-th flower.
Output a single integer Q representing the amount of pollen Gertrude will collect.
5 3 22 15 7 2 1
6
The first bee will collect pollen from the first flower, leaving it with 22 − (2 + 2) = 18 grains remaining. The second bee will also collect from the first flower, leaving it with 18 − (1 + 8) = 9 grains remaining. Finally, Gertrude, the third bee in line, will collect pollen from the second flower, collecting a total of 1 + 5 = 6 pollen, which will be the answer for this test case.
3 10 21 21 21
0
3 9 21 21 21
9