Nile

시간 제한2초메모리 제한1024 MB

요약
무게가 다른 N개의 유물과 짝 비용, 무게 차 임계값 D가 주어질 때, D가 달라지는 Q개의 질의에 대해 최소 운송 비용을 구한다.
난이도

어려움10점 중 8점

유형
정렬, 동적 계획법, 그리디, 이분 탐색
정답자
아직 제출이 없습니다

문제

You want to transport NN artifacts through the Nile. The artifacts are numbered from 00 to N−1N - 1. The weight of artifact ii (0≤i<N0 ≤ i < N) is W\[i]W\[i].

To transport the artifacts, you use specialized boats. Each boat can carry at most two artifacts.

  • If you decide to put a single artifact in a boat, the artifact weight can be arbitrary.
  • If you want to put two artifacts in the same boat, you have to make sure the boat is balanced evenly. Specifically, you can send artifacts pp and qq (0≤p<q<N0 ≤ p < q < N) in the same boat only if the absolute difference between their weights is at most DD, that is ∣W\[p]−W\[q]∣≤D|W\[p] - W\[q]| ≤ D.

To transport an artifact, you have to pay a cost that depends on the number of artifacts carried in the same boat. The cost of transporting artifact ii (0≤i<N0 ≤ i < N) is:

  • A\[i]A\[i], if you put the artifact in its own boat, or
  • B\[i]B\[i], if you put it in a boat together with some other artifact.

Note that in the latter case, you have to pay for both artifacts in the boat. Specifically, if you decide to send artifacts pp and qq (0≤p<q<N0 ≤ p < q < N) in the same boat, you need to pay B\[p]+B\[q]B\[p] + B\[q].

Sending an artifact in a boat by itself is always more expensive than sending it with some other artifact sharing the boat with it, so B\[i]<A\[i]B\[i] < A\[i] for all ii such that 0≤i<N0 ≤ i < N.

Unfortunately, the river is very unpredictable and the value of DD changes often. Your task is to answer QQ questions numbered from 00 to Q−1Q - 1. The questions are described by an array EE of length QQ. The answer to question jj (0≤j<Q0 ≤ j < Q) is the minimum total cost of transporting all NN artifacts, when the value of DD is equal to E\[j]E\[j].

제한

  • 1≤N≤100,0001 ≤ N ≤ 100\\, 000
  • 1≤Q≤100,0001 ≤ Q ≤ 100\\, 000
  • 1≤W\[i]≤1091 ≤ W\[i] ≤ 10^9 for each ii such that 0≤i<N0 ≤ i < N
  • 1≤B\[i]<A\[i]≤1091 ≤ B\[i] < A\[i] ≤ 10^9 for each ii such that 0≤i<N0 ≤ i < N
  • 1≤E\[j]≤1091 ≤ E\[j] ≤ 10^9 for each jj such that 0≤j<Q0 ≤ j < Q

예제

이 문제는 공개된 예제가 없습니다.