Fundraising
Time limit1sMemory limit128 MB
Given a sequence of donation transactions, aggregate the amount each donor gave to each candidate and in total, then report every donor whose per-candidate total exceeds $2100 or whose overall total exceeds $40000. The core task is grouping and summing values by keys, then applying two threshold checks.
- Level
Easy3 of 10
- Topics
- Hash map, Array, Implementation
- Solved
- No attempts yet
Problem
To even begin running a campaign, you need money. How else would you pay for annoying robo-calls, slanderous TV ads against your opponent, or all the suits you have to wear on the campaign trail? There are many ways to raise funds: old-fashioned donations, online ads, expensive fund-raising dinners, and more.
Because campaign donations can be construed (unfortunately, often rightly so) as buying influence over a candidate, campaign-finance laws limit the total amount any person may donate to a candidate or party. Under the law, any individual may contribute at most $2100 to any one candidate, and at most $40000 in total. When these donations are split across many transactions, though, it can be hard to figure out just how much someone gave.
Write a program that reads a sequence of individual donations and determines whether any limits were violated, and if so, which donors are the violators.
Input
The first line contains an integer , the number of data sets. It is followed by data sets of the following form.
The first line of a data set contains three integers , , with , , and . Here is the number of candidates (numbered ), is the number of donors (numbered ), and is the number of transactions.
This is followed by lines, each containing three integers , , . This means that in transaction , donor gave dollars to candidate . The same donor-candidate pair may appear multiple times.
Output
For each data set, first output the line Data Set x: by itself, where is the number of the data set. Then output either the single line No violations, or the line Violators: followed by every donor who broke at least one limit, one per line. List the donors in increasing order of donor number.
A donor is a violator if the total they gave to some single candidate exceeds $2100, or the total they gave across all candidates exceeds $40000.