#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 11 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 2×𝐴2\times 𝐴.

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 𝑥1<𝑥2<<𝑥𝑁𝑥_1< 𝑥_2< \ldots < 𝑥_𝑁 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 𝑥𝑖(1𝑖𝑁)𝑥_𝑖(1 \le 𝑖 \le 𝑁).
  • void answer(vector<int> v):buys your selection of books. This function has to be called with v={i1,,ik}(1i1,,ikN)v=\{i_1,\ldots,i_k\}(1\le i_1,\ldots,i_k\le N) where the iji_j 's are pairwise distinct and satisfy Axi1++xik2×AA\le x_{i_1}+\ldots+x_{i_k}\le 2\times A
  • 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 𝑁=15𝑁 = 15, 𝐾=3𝐾 = 3, 𝐴=42𝐴 = 42, and 𝑆=8𝑆 = 8. 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) 13371337 The first (i.e., easiest) book has difficulty 13371337.
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) 77 The first (i.e., easiest) book has difficulty 77.
skim(15) 2121 The last book has difficulty 2121. Since the sequence of difficulties is strictly increasing, the sequence contains all integers from 77 to 2121. Any valid set of values from the sequence with sum between 4242 and 8484 is acceptable.
answer({11, 15, 7}) You answer with the book numbers 1111, 1515, 77, which correspond to difficulties 1717, 2121, 1313.
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 𝑥1𝑥2𝑥𝑁𝑥_1 𝑥_2 \ldots 𝑥_𝑁 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 ss 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 KNK\le N, 3N,S1053\le N,S\le 10^5, 1A,xi10171\le A,x_i\le 10^{17}, 3K103\le K\le 10

  • Subtask 11 (55 points). S=NS=N, 170N103170\le N\le 10^3, K=3K=3.
  • Subtask 22 (1515 points). S=NS=N, N170N\ge 170.
  • Subtask 33 (1010 points). S170S\ge 170, 1i<N,xi+1xiAK\forall 1\le i <N,x_{i+1}-x_i\le \frac{A}{K}.
  • Subtask 44 (1515 points). S170S\ge 170, 1i<N,xi+1xiA\forall 1\le i <N,x_{i+1}-x_i\le A.
  • Subtask 55 (1515 points). S170S\ge 170.
  • Subtask 66 (2020 points). S40S\ge 40, 1i<N,xi+1xiA\forall 1\le i <N,x_{i+1}-x_i\le A.
  • Subtask 77 (2020 points). S40S\ge 40.