loj#P3558. 「BalticOI 2021 Day1」A Difficult Choice
「BalticOI 2021 Day1」A Difficult Choice
Description
Immortal glory goes to those who win a medal at BOI. As you are keen on being one of them, this is your way to go: training, training, training!
As a first step in your training program, you decided to buy some computer science books. Luckily, your local book store has a special offer with a hefty discount when you buy exactly books.
Now you are to select the books to buy from the set of computer science books (numbered to ) offered in the book store. Your key selection factor is difficulty: Each book has an individual(and fully objective) difficulty , and the total difficulty of a set of books is the sum of their individual difficulties. You don’t want the selected books to be too easy (then you wouldn’t learn enough to win difficulties.that precious medal) or too difficult (then you wouldn’t understand them before the contest starts).To be precise, you want the total difficulty of the selected books to be at least , but not more than .
Judging the actual difficulty of a book requires you to skim through it, but the store owner won’t be happy if you read many books without buying them. She allows you to skim through at most books.Fortunately, she also tells you that the books are sorted by increasing difficulty.
Write a program that assists you in deciding on which books to skim through, and in the end tells you which books to buy.
Communication
This is a communication task. You must implement the function void solve(int N, int K, long long A, int S)
where , , and are as described above. The individual difficulties are initially kept hidden from your program. For each testcase, this function is called exactly once. In the function, you can use the following other functions provided by the grader:
long long skim(int i)
:skims through the -th book and returns its difficulty .void answer(vector<int> v)
:buys your selection of books. This function has to be called with where the 's are pairwise distinct and satisfy 。void impossible()
:states that it is impossible to buy a set of books with the desired difficulty.
If there exists a selection of books with the desired difficulty, you must call answer exactly once. Otherwise, you must call impossible exactly once. Your program will be automatically terminated after a call to one of these two functions.
If any of your function calls does not match the above format, or if you call skim more than times, your program will be immediately terminated and judged as Not correct for the respective testcase. You must not write anything to standard output, otherwise you may receive the verdict Security violation!.
If you use C++, you must include the file books.h in your source code. To test your program locally, you can link your program with sample_grader.cpp
which can be found in the attachment for this task in CMS (see below for a description of the sample grader). The attachment also contains a sampleimplementation with additional explanations as books_sample.cpp
.
If you use Python, you can find a sample implementation as books_sample.py
in the attachment
which also describes the interface for Python submissions.
Sample Interaction
Consider a testcase with , , , and . At the beginning, the grader calls your function solve as solve(15, 3, 42, 8)
. Then, two possible interactions between your program and the grader could look as follows:
Your program | Return value | Explanation |
---|---|---|
skim(1) |
The first (i.e., easiest) book has difficulty . | |
impossible() |
Thanks to your magical intuition, you have decided that there is no valid solution. | |
The solution is correct and is accepted. |
Your program | Return value | Explanation |
---|---|---|
skim(1) |
The first (i.e., easiest) book has difficulty . | |
skim(15) |
The last book has difficulty . Since the sequence of difficulties is strictly increasing, the sequence contains all integers from to . Any valid set of values from the sequence with sum between and is acceptable. | |
answer({11, 15, 7}) |
You answer with the book numbers , , , which correspond to difficulties , , . | |
The solution is correct and is accepted. |
Grader
The sample grader expects on standard input two lines. The first line should contain the four integers , , and . The second line should contain a list of integers, the sequence of difficulties which has to be strictly increasing. Then, the grader writes to standard output a protocol of all grader functions called by your program. At the end, the grader writes one of the following messages to standard output:
Invalid input.
The input to the grader via standard input was not of the above format.
Invalid skim.
The function skim was called with invalid parameters.
Out of books to skim.
The function skim was called more than times.
Invalid answer.
The function answer was called with invalid parameters.
Wrong answer.
The function answer was called with a wrong selection of books.
No answer.
The function solve terminated without calling answer
or impossible
.
Impossible (not checked): s book(s) skimmed.
None of the above cases occurred, the function skim
was called times and the function impossible
was called. It is not checked wether this is the correct
answer.
Correct: s book(s) skimmed.
None of the above cases occurred and the function skim
was called times.
In contrast, the grader which is used for the evaluation of your submission will only output Not correct (for any of the above errors) or Correct. Both the sample grader and the grader used for evaluation will terminate your program automatically whenever one of the above errors occurs or if your program calls answer
or impossible
.
Constraints
We always have , , , 。
- Subtask ( points). , , .
- Subtask ( points). , .
- Subtask ( points). , .
- Subtask ( points). , .
- Subtask ( points). .
- Subtask ( points). , .
- Subtask ( points). .