Prázdny
Prázdny

Task 5

Login required

27. 10. 2023 18:00 | You can get 5 points for the task

Voyage to Mars

In the not-so-distant future, humanity has set its sights on the Red Planet, Mars. A team of ambitious space pioneers is preparing for the most significant journey in the history of space exploration - colonization of Mars. The countdown to launch has begun, and the rocket is scheduled to depart for Mars tomorrow. The mission is fraught with challenges, and the key to its success lies in optimizing the payload of the Mars-bound rocket, but there's no time to find the perfect solution.

 

To ensure the mission's success, a group of brilliant scientists has been assigned the last-minute task of selecting and prioritizing machines based on their usefulness. These machines come in various shapes and sizes, but they all serve vital functions in the colonization process. Some machines are responsible for resource extraction, while others are crucial for habitat construction, life support, and scientific research.

 

The scientists have carefully rated each machine for its usefulness, providing a numerical score to represent its importance. Additionally, they have assessed the size of each machine, which must be taken into account when loading the rocket. The rocket's payload capacity is limited, and every bit of space must be utilized efficiently to ensure that all necessary machines are sent to Mars.

 

The urgency is real, and time is running out. The scientists must develop a program that helps the colonization team make the most of the limited space in the rocket, and they don't have the luxury of finding the perfect solution. They need to design an algorithm that quickly selects the machines to be included in the payload, ensuring that the total usefulness is maximized without exceeding the rocket's size limit.

 

The science team is fully aware of the fact that finding perfect solution is not easy. Your challenge is to create an algorithm that operates under tight time constraints, selecting the machines for the rocket's payload as efficiently as possible.

 

 

 

 

 

Select machines to maximize usefulness while staying within the payload size limit.

JSON FILE WITH INPUT HERE

 

 

 

Input file:

{ "items": [

    { "id": ID0, "value": value0, "weight": weight0 },
    { "id": ID1, "value": value1, "weight": weight1 },
    { "id": ID2, "value": value2, "weight": weight2 },
  ],
  "capacity": weight_limit }

 

Output:

Total value: total_value
Total weight: total_weight
items:
ID0
ID1

 

Example:
Input:

{
  "items": [
    { "id": 0, "value": 26, "weight": 5 },
    { "id": 1, "value": 36, "weight": 10 },
    { "id": 2, "value": 41, "weight": 14 }
  ],
  "capacity": 20
}

 

Output:
Total value: 67
Total weight: 19
items:
0
2

SOLUTION HERE

 

.