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

31063번 - Candy Cane Feast 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB106441331839.552%

문제

Farmer John's cows have quite the sweet tooth, and they especially enjoy eating candy canes! FJ has $N$ total cows, each with a certain initial height and he wants to feed them $M$ candy canes, each also of varying height (1ドル\le N,M\le 2\cdot 10^5$).

FJ plans to feed the candy canes one by one to the cows, in the order they are given in the input. To feed a candy cane to his cows, he will hang the candy cane so that initially the candy cane is just touching the ground. The cows will then line up one by one, in the order given by the input, and go up to the candy cane, each eating up to their height (since they cannot reach any higher). The candy cane stays suspended in place where it is initially set up and is not lowered to the ground, even after cows eat the bottom of the candy cane. It is possible a cow may eat nothing during her turn, if the base of the candy cane is already above that cow's height. After every cow has had their turn, the cows grow in height by how many units of candy cane they ate, and Farmer John hangs the next candy cane and the cows repeat the process again (with cow 1 again being the first to start eating the next candy cane).

입력

The first line contains $N$ and $M$.

The next line contains the initial heights of the $N$ cows, each in the range $[1,10^9]$.

The next line contains the heights of the $M$ candy canes, each in the range $[1,10^9]$.

출력

The final heights of each of the $N$ cows on separate lines.

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

제한

예제 입력 1

3 2
3 2 5
6 1

예제 출력 1

7
2
7

힌트

The first candy cane is 6ドル$ units tall.

  1. The first cow eats the portion of the first candy cane up to height 3ドル,ドル after which the remaining portion of the first candy cane occupies heights $[3,6]$.
  2. The second cow is not tall enough to eat any of the remaining portion of the first candy cane.
  3. The third cow eats two additional units of the first candy cane. The remaining portion of the first candy cane, occupying heights $[5,6],ドル is not eaten.

Next, each cow grows by the amount she ate, so the heights of the cows become $[3+3, 2+0, 5+2]=[6, 2, 7]$.

The second candy cane is 1ドル$ unit tall, and the first cow eats all of it.

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2023 December Contest > Bronze 1번

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

출처

대학교 대회

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

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