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

Candy

설명

In the ancient city of Ica, there is said to be a palace with wealth beyond imagination. Inside, there is a corridor with \(N\) boxes of candy from all over the world. Travellers passing by can take as much candy as they want, provided that they pay its weight in gold.

The boxes of candy are numbered \(0\) to \(N-1\) from left to right. In box \(i\), there are \(a_i\) units of candy left, where \(a_i\) is a non-negative integer.

As the guardian of the palace, you would like to move the boxes around so that boxes with a lot of candy end up closer to the entrance.

You are given the array \(a_0, a_1, \ldots, a_{N-1}\), as well as the numbers \(F\) and \(T\). In a single operation, you are allowed to swap two adjacent elements of \(a_0, a_1, \ldots, a_{N-1}\). What is the minimum number of operations required so that the first \(F\) elements of the array sum to at least \(T\)?

제약
  • \(1 \le N \le 100\).
  • \(1 \le F \le N\).
  • \(0 \le T \le 10^{11}\).
  • \(0 \le a_i \le 10^9\) for \(i = 0, 1, \ldots, N-1\).

Note: The numbers in the input may not fit in a \(32\)-bit integer, so be aware of overflows if you are using C++.

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

Group | Score | Limits 1 | 6 | \(N \le 2\) and \(a_i \le 100\) for \(i = 0, 1, \ldots, N-1\) and \(T \le 10^9\) 2 | 19 | \(a_i \le 1\) for \(i = 0, 1, \ldots, N-1\) 3 | 16 | \(N \le 20\) 4 | 30 | \(a_i \le 100\) for \(i = 0, 1, \ldots, N-1\) 5 | 29 | No additional constraints

입력 형식

The first line of the input contains three integers, \(N\), \(F\), and \(T\).

The second line of the input contains \(N\) integers \(a_0, a_1, \ldots, a_{N-1}\).

출력 형식

If it is impossible to achieve the objective using the operations, print NO.

Otherwise, print a single integer, the minimal number of operations.

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

Subtask 1

6점

None

Subtask 2

19점

None

Subtask 3

16점

None

Subtask 4

30점

None

Subtask 5

29점

None

예제 1
입력
6 2 27
10 4 20 6 3 3
출력
1
예제 2
입력
6 5 5000000000
1000000000 1000000000 0 1000000000 1000000000 1000000000
출력
3
예제 3
입력
3 2 100
20 30 60
출력
NO
예제 4
입력
1 1 100
100
출력
0
문제 정보

rip 작성

출처 EGOI 2023

평가 및 의견

Candy

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

Log in to rate problems.

개별 의견

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

풀이 제출

Candy

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