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

13050번 - Maximal Sum 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB150353024.194%

문제

Marty wants to get back to the future from the past. But the computer system of his time machine is broken, so he needs to make some calculations by himself and then enter the results.

Marty has two arrays of integers: a[1..n] and b[1..m]. For each bj Marty needs to find the segment a[l..r] such that each element in it is greater or equal to bj and the sum of elements a[l] + a[l + 1] + ... + a[r] is maximal possible. These sums must be entered into time machine's computer system to get Marty back to the future.

Help him, write the program to solve this problem.

입력

The first line of input contains two integers n and m (1 ≤ n, m ≤ 105) — the sizes of arrays a and b, respectively.

The second line contains n integers ai ( -109 ≤ ai ≤ 109).

The third line contains n integers bj ( -109 ≤ bj ≤ 109).

출력

Output m integers, the j-th of them must be the required maximal sum for bj. If there is no such segment in a array, output 0 instead.

제한

예제 입력 1

5 5
-1 2 3 4 -5
-5 4 10 2 -1

예제 출력 1

9 4 0 9 9

예제 입력 2

5 5
3 -2 3 -5 -3
-1 -2 -3 -4 -5

예제 출력 2

3 4 4 4 4

힌트

출처

Contest > Russian Code Cup > 2016 > RCC 2016 WarmUp Round E번

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

출처

대학교 대회

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

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