You are the organizer attempting to hold the lantern festival, this year. To evoke the happiness and excitement of participants, you prepare an activity called Lucky Envelope. Everyone who entered the festival has a chance to get it.
Because it is a quite huge festival, you divide the whole activity into N places, where N is an integer.
These places are numbered from level 0 to level (N-1). Each place has a ticket station that handles the registration process for incoming families.
Similar to HW1, families must complete a registration process upon arrival:
Ticket Stations & Payment Structure
Each ticket station serves families based on the amount they pay. Each level has a defined payment range and provides a lucky envelope whose total money is calculated as ten times the upper limit of that range.
For N ticket stations:
Reminder 1:
If a family's payment exceeds the upper limit of the highest level, they are directed to the last station.
Family Information
Each minute, a certain number of families arrive at the festival. Each family is identified by:
For example, a family entry may be represented as:
F0, 10, 100 (This is just for the illustration, not for the input format)
Indicating Family 0, consisting of 10 people, and they will pay a total of 100 dollars.
At this moment, 3 families are arriving. F0,10,100 and F1,5,700 and F2,1,800.
Now the status at Station 2:
The festival’s registration area is divided into two regions:
Once a family completes registration (meaning they have successfully paid the required money), they can proceed to join the festival and participate in the Lucky Envelope activity.
1. Suspicious Family
A family is considered suspicious if their average money per person is 10,000 or more
average money per person = The total money they will pay divided by the number of people (using integer division)
Since it is highly unusual for someone to spend 10,000 dollars or more just to attend the festival, such families will be subjected to additional identity verification, including questioning about their source of money like “Who are you?” “Where does your money come from?”.
Special Rule for Suspicious Family:
2. Grouping Family
Families arriving at the same time will group together if they meet the following conditions:
Grouping Effect:
This rule allows families to upgrade their ticket station and potentially receive a higher-value lucky envelope.
Illustration for grouping: Case with 3 Ticket Stations (N = 3)
Note that
A grouping family is considered as 1 family.
Each grouping operation can only group 2 families.
One family can only group once. Once a family is grouped with a family, they can not group with another.
If there are multiple ways of grouping, group the family from the front. (once you group a pair of families together, you have to continue to search for other potential pairs of grouping families)
Example: F10,4,500 F11,4,500 F12,1,500 F13,1,500
→ Group F10 and F11, forming F10,8,1000
→ Group F12 and F13, forming F12,2,1000
Instead of Group F11 and F12
A grouping family can be a suspicious family if it meets the condition of a suspicious family.
Originally suspicious families also can become unsuspicious, if they don’t meet the condition after grouping.
Lucky Draw Order Rule (After the simulation ends)
After the last minute, for each place families who have entered the festival will participate in the final lucky draw. Although everyone has a chance to win, we assign a specific draw order based on the following rule:
Draw Order Arrangement:
We prioritize families who contribute more payment per person. The arrangement is as follows:
First Half – High Contribution Families
Families whose (payment)-to-(family-size) ratio is equal to or greater than a certain threshold (H) will be placed in the first half of the draw order.
Second Half – The Rest
Families not meeting the above ratio will be placed in the second half.
Ordering Within Each Half
Within each half (first half and second half), families are sorted by their entry order (i.e., the earlier in the front).
First Line
The first line contains three integers N, M, and H separated by a space:
Following M Lines
Each of the next M lines represents the families arriving at that specific minute (from minute 0 to minute M-1).
Example: 0,1,90 1,1,90 2,2,300 3,3,200
Input Constraint:
Here is a reference code in C++ that may help you parse the family line.
You can also write your own code
//if you attempt to use please include these headers
#include <vector>
#include <sstream>
#include <iomanip>
string line;
getline(cin, line);
if (line != "0") { // Process only non-zero lines
stringstream line_stream(line);
string famData;
// line: 0,1,1 1,1,1 2,2,2
while (line_stream >> famData) { // Split by spaces (each family)
stringstream family_stream(famData);
string temp;
vector<int> values; //will include number, #people, money
while (getline(family_stream, temp, ',')) { // Split by commas
values.push_back(stoi(temp));
}
if (values.size() == 3) { // Ensure valid data
/*
//testing the input
cout<<"Family info:"<<"\n";
cout<<"Family number:"<<values[0]<<"\n";
cout<<"number of people:"<<values[1]<<"\n";
cout<<"money:"<<values[2]<<"\n";
*/
/*
maybe some additional code here
*/
}
/*
maybe some additional code here
*/
}
}
For each place (ticket station), display the following information:
Place ID
Comparing the total money collected to the envelope you will give for the place. Show if the place
Make profit , followed by how much profit you make for the place.
Lose money, followed by how much money you lose for the place.
Break even
List the families currently queuing (frontmost family at the top).
Show the family currently undergoing registration.
List families that have completed registration (entered the place), in reverse order (most recent entry at the top).
Show the draw order of the place with their Family Numbers.
Example: Draw order: 3 4 5 0 1 2 (there is a space at the end of the line)
Use a new line to separate each place’s output.
Ensure there is a new line at the end of the entire output.