Health Plan Comparison
Time limit1sMemory limit128 MB
Parse free-text health plan descriptions to extract premiums and copay rules, then compute each plan's total yearly cost across the given visits.
- Level
Medium7 of 10
- Topics
- String, Implementation, Simulation, Greedy
- Solved
- No attempts yet
Problem
In a competitive market, private health insurance is supposed to let each patient pick the plan that best fits their needs. In practice this is hard: it is difficult to predict in advance which benefits you will actually use, and reading a plan's fine print to tell what is and isn't covered is not trivial. In this problem you are given descriptions of several health plans (their premiums and co-payments), together with your projected doctor visits for the coming year, and you must compute the total cost of each plan.
The descriptions are parsed as follows.
- A sentence always ends with a period
.. All other punctuation (spaces, line breaks, commas, semicolons) can be ignored. - The text mixes upper and lower case; comparisons are case-insensitive.
- The text contains only letters, digits, spaces, line breaks, the punctuation marks
.,,,;, and the characters%and $. All numbers are integers.
The descriptions talk about the following.
- Plan. If a sentence contains the word
plan, the next word in that sentence is the name of the plan being described. All information up to (but not including) the next sentence that contains the wordplanrefers to that plan. - Premium. In a sentence containing the word
premium, the integer that has a dollar sign immediately before or after it, or is immediately followed by the worddollars, is the plan's premium (in dollars). There is exactly one such number. - Copayment (copay). In a sentence containing the word
copaymentorcopay:- An integer with a dollar sign before or after it, or followed by the word
dollars, is your maximum copay in dollars (you are never asked to pay more). - An integer followed by a percent sign or by the word
percentexpresses the copay as a percentage of the actual visit cost. - If both a dollar amount and a percentage are given, the copay is the minimum of the two corresponding amounts.
- A copay can never exceed the cost of the visit itself. For example, if the copay is $100 and the visit costs $50, you pay only $50.
- An integer with a dollar sign before or after it, or followed by the word
- Per visit vs. total. A copay sentence applies either to each visit separately or to all visits together, depending on whether it contains the words
per visitortotal. If neither appears, the copay is a total. If both appear, it is per visit. (Premiums have no per-visit/total distinction.) - Each sentence contains at most one of the words
premiumorcopayment/copay, and contains the wordplanat most once. - If a premium or copayment is not specified, it is
0. - If several values are given for a plan's premium or copayment, the last one specified is used.
After the plan descriptions you are given a list of doctor visits, each described by a single number: the cost of that visit. Your task is to report the total expense (premium plus copayments) for each plan.
Input
The first line contains the number K of data sets. Each of the K data sets has the following form.
- The first line contains two integers
mandn(). - The next
mlines are the text describing the health plans. Each line has at most 80 characters. There is always at least one plan. A line may contain several sentences, and a sentence may span several lines. - The following
nlines each contain one integer: the cost of one doctor visit.
Output
For each data set, first print Data Set x: on its own line, where x is the data set's number (starting from 1). Then print, one per line, the total amount of money you must spend (premium plus copays) for each plan, rounded to two decimals. The plans are listed in the order in which they are first mentioned in the text. Consecutive data sets are separated by a blank line.