Files
contests/usaco/ch1/gift1.cpp

77 lines
1.5 KiB
C++

/*
ID: philipp17
PROG: gift1
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
using namespace std;
int main() {
ofstream fout ("gift1.out");
ifstream fin ("gift1.in");
int np;
fin >> np;
map<string, int> names_to_index;
map<int, string> index_to_name;
vector<int> bank(np, 0);
for(int i = 0; i < np; ++i){
string s;
fin >> s;
names_to_index[s] = i;
index_to_name[i] = s;
}
for(int i = 0; i < np; ++i){
string name;
int money, ng;
fin >> name >> money >> ng;
// cout << name << " " << money << " " << ng << endl;
if(ng == 0){
continue;
}
vector<string> receivers(ng);
// cout << ng << endl;
for(int j = 0; j < ng; ++j){
fin >> receivers[j];
}
// for(string s: receivers){
// cout << s << " ";
// }
if(money == 0){
continue;
}
int money_per_person = money / ng;
for(const string &receiver : receivers){
bank[names_to_index[receiver]] += money_per_person;
}
bank[names_to_index[name]] -= money_per_person * ng;
}
// Printing the output
for(int i = 0; i < np; ++i){
fout << index_to_name[i] << " " << bank[i] << endl;
}
return 0;
}