0% found this document useful (0 votes)
8 views3 pages

BDOI Knapsack (En)

The document describes a competitive programming problem involving a magician named Tasmeem and a challenger named Pepe, where Pepe must optimize the selection of items for a knapsack based on their costs and weights. Pepe can change the costs of the items a limited number of times and must guess the maximum original cost of the optimal set of items within a specified range. The implementation requires creating a function to interact with Tasmeem and adhere to specific constraints regarding the number of operations and total cost limits.

Uploaded by

lm.tonay1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

BDOI Knapsack (En)

The document describes a competitive programming problem involving a magician named Tasmeem and a challenger named Pepe, where Pepe must optimize the selection of items for a knapsack based on their costs and weights. Pepe can change the costs of the items a limited number of times and must guess the maximum original cost of the optimal set of items within a specified range. The implementation requires creating a function to interact with Tasmeem and adhere to specific constraints regarding the number of operations and total cost limits.

Uploaded by

lm.tonay1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Bangladesh Olympiad in Informatics knapsack

National Round Day 2 Tasks


February 21-22, 2025 English

Knapsack
Tasmeem the magician has N items. The cost of ith item is C[i] taka, and the weight of ith item is
W [i] kg. Tasmeem also has a sack that can contain any number of items as long as their total
weight is at most X kg. An emerging magician Pepe has challenged Tasmeem to play a game with
him.

First, Tasmeem will give Pepe the original costs of all N items. Then Pepe can do the following
operation at most 32 times:

Pepe will change the cost of each item. After that, the cost of ith item will be R[i] (0 ≤
R[i] ≤ 107 ). He will give the new costs to Tasmeem with a non-negative integer K .
Tasmeem will try to find the optimal set of items that he can put into the sack such that the
sum of changed costs (according to R) are maximised. Suppose the optimal total cost is K ′
. He will tell Pepe the value of min(K, K ′ )

After that, Pepe need to guess the maximum total original cost (according to C ) for the optimal
set. Since Tasmeem is very generous, Pepe will get points if the cost he guessed is in between 99%
and 100% of the actual cost (inclusive). However, there are some rules:

As mentioned earlier, Pepe cannot do the operation more than 32 times.


Sum of K over all the operations cannot exceed 106 .

Help Pepe crack the game.

Implementation Details

On behalf of Pepe, you should implement the following procedure.

int guess_knapsack(std::vector< int > C)

C : an array of N integers describing original costs.


The procedure should return an integer S , which must be in between 99% and 100% of the
maximum total original cost of items Tasmeem can put in his sack together.
This procedure is called exactly once for each test case.

The above procedure can make calls to the following procedure to interact with Tasmeem.

int try_knapsack(std::vector< int > R, int K)

knapsack (1 of 3)
R: an array of N non-negative integers, describing the changed costs. Values of R must not
exceed 107 .
K : a non-negative integer described above.
This procedure returns an integer representing Tasmeem’s reply.
SK should not exceed 106 over all calls, where SK is the sum of K over all calls in a single
​ ​

test.
This procedure can be called at most 32 times.

Your code must scan anything from the standard input (i.e. use ‎
scanf‎or ‎
cin‎) or print anything to
the standard output (i.e. use ‎printf‎or ‎
cout‎
). However, you can print debugging information to
stderr. For communication, use the functions described above.

The grader is not adaptive, that is, the values of W and X are fixed before a call to
guess_knapsack‎is made.

Constraints
1 ≤ N ≤ 100
1 ≤ C[i] ≤ 107 for (1 ≤ i ≤ N )
0 ≤ X ≤ 5000
1 ≤ W [i] ≤ 5000 for (1 ≤ i ≤ N )

X and W are hidden from contestants and only used for internal processes.

Subtasks

Subtask Score Additional constraints

1 10 1 ≤ C[i] ≤ 100 for (1 ≤ i ≤ N )


2 10 N =5
3 80 No additional constraints

For the last subtask, your score is determined using a formula. Let’s assume SK is the maximum

sum of K over all operations in a test case. Your final score will be calculated using the following
table:

SK ​ Score

SK > 106

0
2
106 − SK
300N < SK ≤ 106 ( 6 ) × 80

10 − 300N

SK ≤ 300N

80

knapsack (2 of 3)
Example

Let’s consider the following case.

N =5

C = {100, 200, 500, 40, 40}

W = {1, 1, 10, 2, 1}

X=2

The following call will be made.

guess_knapsack({100, 200, 500, 40, 40})‎

This procedure may call ‎


try_knapsack‎as follows.

try_knapsack({100, 100, 10, 100, 400}, 100)‎

In this case, the maximum total cost of items that Tasmeem can put in his sack together is 500 (by
taking the first and the last items). However, this procedure will return 100 since K = 100 < 500.

The solution using original cost is 300 (by taking the first two items). In order to get points,
guess_knapsack‎must return any integer in between 99% ⋅ 300 = 297 and 300 (inclusive).

Sample Grader

Input format:

line 1: N X
line 2: C[1] C[2] … C[N ]
line 3: W [1] W [2] … W [N ]

If you violate any rule, you will get an output message accordingly. Otherwise, the grader will
output in the following format:

line 1: ‎
Contestant:‎A
line 2: ‎
Original:‎B
line 3: ‎
Sum of Ks:‎SK ​

Here, A is the output of ‎


guess_knapsack‎
, B is the original solution, and SK is the sum of K over

all calls to ‎
try_knapsack‎.

Note that the grader used for actual evaluation is different from the sample grader.

knapsack (3 of 3)

You might also like