RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00693

Benzinska

설명

The camp in Čakovec has already started, but Mr. Malnar is still visiting Zagreb’s
restaurants. Wanting to burn the calories he consumed, he decided to cycle to
Čakovec.
Mr. Malnar starts his journey from Zagreb (\(x = 0\)) with an initial energy of \(D\)
and wants to reach Čakovec, which is \(X\) meters away from Zagreb (\(x = X\)). Each
meter of the journey requires one unit of energy. To avoid passing out, his energy
must not become negative at any point during the trip.
There are \(n\) restaurants along the way, with the \(i\)-th restaurant located at the \(x_{i}-th\) meter from the
starting point. Multiple restaurants can be located at the same position. If Mr. Malnar decides to dine at
the \(i\)-th restaurant, his energy increases by \(y_{i}\). He may not eat at the same restaurant multiple times.
Help him determine the minimum number of restaurants he must dine at to safely reach Čakovec.

제약
입력 형식

In the first line of input, there are three integers \(n\), \(D\), and \(X\) (\(1 \le n \le 2 \cdot 10^{5}\), \(1 \le D\), \(X \le 10^{9}\)),
representing the number of restaurants, the initial energy, and the distance between the cities.
In the second line of input, there are \(n\) integers \(x_{i}\) (\(1 \le x_{i} < X\)), representing the positions of the
restaurants.
In the third line of input, there are \(n\) integers \(y_{i}\) (\(1 \le y_{i} \le 10^{9}\)), representing the energy Mr. Malnar gains
by dining at each respective restaurant.

출력 형식

In a single line of output, print the minimum number of restaurants Mr. Malnar must dine at to safely
reach Čakovec. If it is not possible to reach Čakovec, print ’-1’ (without quotes).

서브태스크
서브태스크점수설명

1

15점

\(y_{i} = y_{j}\) for every \(i\), \(j\)

2

30점

\(n \le 1\,000\)

3

25점

No additional constraints. Probni primjeri input 5 5 12 3 4 7 8 11 3 2 1 2 1 output 3 input 5 10 40 1 20 30 2 38 7 7 7 7 7 output 5 input 4 5 12 3 6 9 10 2 1 2 2 outp\(ut -1\) Clarification of the first example: At \(x = 3\), Mr. Malnar will have 2 energy units left. At the first restaurant, he will dine, and his energy will increase to \(2 + 3 = 5\). At \(x = 4\), he will have 4 energy units left. At the second restaurant, he will dine, and his energy will increase to \(4 + 2 = 6\). At \(x = 8\), he will have 2 energy units left. At the fourth restaurant, he will dine, and his energy will increase to \(2 + 2 = 4\). In total, he dined at three restaurants.

예제 1
입력
5 5 12
3 4 7 8 11
3 2 1 2 1
출력
3
예제 2
입력
5 10 40
1 20 30 2 38
7 7 7 7 7
출력
5
예제 3
입력
4 5 12
3 6 9 10
2 1 2 2
출력
-1
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2024/2025 Contest 4

평가 및 의견

Benzinska

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Benzinska

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8