What is the minimal total weight of cylinders

Assignment Help JAVA Programming
Reference no: EM13161165

A scuba diver uses a special equipment for diving. He has a cylinder with two containers: one with oxygen and the other with nitrogen. Depending on the time he wants to stay under water and the depth of diving the scuba diver needs various amount of oxygen and nitrogen. The scuba diver has at his disposal a certain number of cylinders. Each cylinder can be described by its weight and the volume of gas it contains. In order to complete his task the scuba diver needs specific amount of oxygen and nitrogen. What is the minimal total weight of cylinders he has to take to complete the task?

Example

The scuba diver has at his disposal 5 cylinders described below. Each description consists of: volume of oxygen, volume of nitrogen (both values are given in litres) and weight of the cylinder (given in decagrams):

3 36 120
10 25 129
5 50 250
1 45 130
4 20 119

If the scuba diver needs 5 litres of oxygen and 60 litres of nitrogen then he has to take two cylinders of total weight 249 (for example the first and the second ones or the fourth and the fifth ones).

Task

Write a program that for each test case:

  • reads scuba diver's demand for oxygen and nitrogen, the number of accessible cylinders and their descriptions;
  • computes the minimal total weight of cylinders the scuba diver needs to complete his task;
  • outputs the result.

Note: the given set of cylinders always allows to complete the given task.

Input

The number of test cases c is in the first line of input, then c test cases follow separated by an empty line.

In the first line of a test case there are two integers ta separated by a single space, 1 <= t <= 21 and 1 <= a<= 79. They denote volumes of oxygen and nitrogen respectively, needed to complete the task. The second line contains one integer n, 1 <= n <= 1000, which is the number of accessible cylinders. The following n lines contain descriptions of cylinders; i-th line contains three integers tiaiwi separated by single spaces, (1 <= ti<= 21, 1 <= ai <= 79, 1 <= wi <= 800). These are respectively: volume of oxygen and nitrogen in the i-th cylinder and the weight of this cylinder.

Output

For each test case your program should output one line with the minimal total weight of cylinders the scuba diver should take to complete the task.

Example

Sample input:
1
5 60
5
3 36 120
10 25 129
5 50 250
1 45 130
4 20 119

Sample output:
249

 

 

Reference no: EM13161165

Questions Cloud

Method called wordlengths that accepts a scanner : Write a method called wordLengths that accepts a Scanner representing an input file as its argument. Your method should read from the given file.
Method named isallvowels that returns : Write a method named isAllVowels that returns whether a String consists entirely of vowels (a, e, i, o, or u, case-insensitively). If every character of the String is a vowel, your method should return true. If any character of the String is a non-vo..
Multidimensional arrays : multidimensional arrays to life, let's consider a specific example: How can you visualize a 4-dimensional array? How can you give meaning to each dimension this array has? What kind of application would such an array be useful for?
What is the energy required to move a mole of urea out : What is the energy required to move a mole of urea out of the kidney cells and into the urine?
What is the minimal total weight of cylinders : A scuba diver uses a special equipment for diving. He has a cylinder with two containers: one with oxygen and the other with nitrogen. Depending on the time he wants to stay under water and the depth of diving the scuba diver needs various amount of ..
Create a file, shared.txt : When your program starts, it shall do the following:1. Create a file, SHARED.txt, in the current directory (cwd). 2. Write it's pid (Process ID) followed by a Carriage Return and Newline in the file.
State divers breathing compressed air : The solubility of N2 in blood can be a serious problem (the "bends") for divers breathing compressed air (78% N2 by volume) at depths greater than 50 ft.
Hasanodddigit that returns whether any digit : d named hasAnOddDigit that returns whether any digit of a positive integer is odd. Your method should return true if the number has at least one odd digit and false if none of its digits are odd. 0, 2, 4, 6, and 8 are even digits, and 1, 3, 5, 7, 9 a..
Determine the microcanonical partition function : Determine the microcanonical partition function, omega. Determine fundamental relation of system, using Stirling's approximation Determine the energy and heat capacity for the system as a function of temperature using Stirling's approximation. Det..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write function in javascript to compute person-s gross pay

Write the function using JavaScript syntax to compute a person's gross pay for a week. The function should receive the number of hours worked and the rate of pay per hour.

  Java program to store temperatures in two-dimensional array

Write the Java program which uses two-dimensional array to store highest and lowest temperatures for each month of the year. Program must output average high,average low,

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Create java program to describe inheritance and polymorphism

Create a Java program based on the geometric shapes example described at the beginning of this lesson using Classes Square, Triangle, Rectangle, and Circ leto help describe inheritance and polymorphism.

  Java application prompt user to put in integer from keyboard

Write a java application that performs the following task: prompt user to put in an integer from the keyboard, search for the user input from the array created in step 1.

  Create a bar chart that illustrates sales.

Hal's Used Cars has four salespeople named Pam, Leo, Kim, and Bob. Accept values for the number of cars sold by each salesperson in a month, and create a bar chart that illustrates sales. Save the file as BarGraph.java.

  Create java program to find number of days left in that year

Create a Java program called "DaysLeftInYear.java" that outputs the number of days left in that year. use the calendar class to represent dates. Use the DateFormat class to display the current date in the output.

  Implementation the two classes

Program Specifications: In the new implementation, the two classes, Student and Grades, are defined with the following operations/methods.

  Consider a typical certification hierarchy

Why might Bob still not trust that the certificate for Alice truly establishes Alice as the owner of the public key in the certificate?

  Java program that prompts the user to input an integer

Write a Java program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

  Modify the scholarship application

Modify the Scholarship application so that if a user enters a grade point average under 0 or over 4.0, or a negative value for either of the activities, an error message appears.

  Java-s ability to derive new fonts from existing ones

Find out where on your system these font libraries are located. When you do, please specify the operating system and the location (folder/directory) where you found them. Discuss Java's ability to derive new fonts from existing ones.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd