#include #include #include #define MAX_TOTAL_DONATIONS 40000 #define MAX_PER_CANDIDATE_DONATIONS 2100 using namespace std; struct donations { vector per_candidate; int total; bool violator; }; void process_record(ifstream & infile, int num_donors, int num_candidates, int num_transactions) { vector donors(num_donors+1); vector violators; int d, c, m; for (int i = 0; i < num_donors+1; i++) { donors.at(i).per_candidate.resize(num_candidates+1); for (int k = 0; k < num_candidates+1; k++) donors.at(i).per_candidate.at(k) = 0; donors.at(i).total = 0; donors.at(i).violator = false; } for (int j = 0; j < num_transactions; j++) { infile >> d >> c >> m; donors.at(d-1).total += m; donors.at(d-1).per_candidate.at(c-1) += m; if (donors.at(d-1).total > MAX_TOTAL_DONATIONS || donors.at(d-1).per_candidate.at(c-1) > MAX_PER_CANDIDATE_DONATIONS) donors.at(d-1).violator = true; } for (int a = 0; a < num_donors; a++) { if (donors.at(a).violator) violators.push_back(a+1); } if (violators.empty()) cout << "No violations" << endl; else { cout << "Violators:" << endl; for (vector::iterator iter = violators.begin(); iter != violators.end(); iter++) cout << *iter << endl; } } int main() { ifstream infile("money.in"); int records, num_donors, num_candidates, num_transactions; infile >> records; for (int i = 0; i < records; i++) { infile >> num_candidates >> num_donors >> num_transactions; cout << "Data Set " << i+1 << ":" << endl; process_record(infile, num_donors, num_candidates, num_transactions); } return 0; }