Logo
(追記) (追記ここまで)

29990번 - Extracting Pollen 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.5 초 1024 MB31161583.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.

  1. The first rule pertains to the amount of pollen grains collected: when a bee visits a flower, it must gather the sum of the digits in its current pollen quantity. For instance, if a bee visits a flower with 123 pollen grains, it must collect 1 + 2 + 3 = 6 grains, leaving the flower with 123 − 6 = 117 grains. Similarly, if the flower holds 201 grains, the bee must gather 2 + 0 + 1 = 3 grains, leaving 198 grains remaining.
  2. All bees must form a queue at the start of the day; the bee at the front of the queue must collect pollen from one of the flowers with the largest amount pollen. If a bee visits a flower with 0 grains of pollen, it collects zero grains. After collecting pollen from a flower, the bee ends its shift and returns to the hive.

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.

제한

예제 입력 1

5 3
22 15 7 2 1

예제 출력 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.

예제 입력 2

3 10
21 21 21

예제 출력 2

0

예제 입력 3

3 9
21 21 21

예제 출력 3

9

힌트

출처

ICPC > Regionals > Latin America > Sub-Regional Brasil do ACM ICPC > Maratona de Programação da SBC 2023 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /