#P8122. [BalticOI 2021] A Difficulty Choice (Day1)
[BalticOI 2021] A Difficulty Choice (Day1)
Description
You are determined to get accepted on BalticOI, and the way to do that is studying. You walk into a bookstore. There are books on the shelf, numbered from to . The difficulty of the -th book is . You want to choose books out of these books for studying. You do not want the material to be too easy or too hard, so you want to ensure that the sum of difficulties of these books lies in the interval .
Unfortunately, you do not know the exact values of , so you need to skim the books to learn their difficulties. The shop owner is a neat freak and does not want you to skim too many books, so you are allowed to skim at most books and then decide. Luckily, you are told that as the book index increases, the difficulty is strictly increasing.
Please write a program that, by skimming books, buys the books you need, or reports that it is impossible.
Interaction Format
This is an interactive problem. You need to write the function void solve (int N, int K, long long A, int S). are defined above, and it is guaranteed that . This function is called exactly once.
You may also call the following functions:
long long skim (int i)skims the -th book to obtain its difficulty .void answer (vector<int> v)buys the books you need. Here , and it must satisfy:
void impossible ()reports that it is impossible to buy books as required.
If there exist books satisfying the requirement, you must call answer exactly once. Otherwise, you must call impossible exactly once. After that, the program stops automatically.
If your function calls do not follow the format above, or if you call skim more than times, the program stops automatically and the test will be judged as Not correct. You must not output anything to standard output, otherwise you will be judged as Security violation.
If you use C++, please include the books.h header file. If you want to check the correctness of your program, you can download sample_grader.cpp and books_sample.cpp from the attachments below; they are used for correctness checking and as an example, respectively.
If you use Python, you can download books_sample.py from the attachments below for testing.
The interactive library expects two lines on standard input:
- The first line contains four integers, .
- The second line contains integers, .
Then the interactive library will call your program. Finally, the interactive library will output a message to standard output:
| Message | Meaning |
|---|---|
| Invalid input. | The format of standard input is wrong |
| Invalid skim. | The call to skim is invalid |
| Out of books to skim. | skim is called more than times |
| Invalid answer. | The call to answer is invalid |
| Wrong answer. | The vector passed to answer does not satisfy the requirement |
| No answer. | The solve function did not call either answer or impossible |
| Impossible (not checked): s book(s) skimmed. | None of the above happened; skim was called times, and impossible was called when an answer exists |
| Correct: s book(s) skimmed. | None of the above happened; skim was called times |
For the error cases above, the interactive library will only return Not correct, or Correct when your solution is correct. Whenever any of the errors above occurs, or when your program calls answer or impossible, the program will be stopped automatically.
Input Format
See “Interaction Format”.
Output Format
See “Interaction Format”.
15 3 42 8
Hint
Sample 1 Explanation
, , , . Below are two possible sequences of calls that would be accepted:
Example 1:
| Your program | Return value |
|---|---|
skim(1) |
|
impossible |
- |
Example 2:
| Your program | Return value |
|---|---|
skim(1) |
|
skim(15) |
|
answer({11,15,7}) |
- |
Constraints and Assumptions
This problem uses bundled testdata.
- Subtask 1 (5 pts): , , .
- Subtask 2 (15 pts): , .
- Subtask 3 (10 pts): , .
- Subtask 4 (15 pts): , .
- Subtask 5 (15 pts): .
- Subtask 6 (20 pts): , .
- Subtask 7 (20 pts): .
For of the testdata, , , , .
Note
Translated from BalticOI 2021 Day1 A A Difficulty Choice.
Translated by ChatGPT 5
京公网安备 11011102002149号