70 lines
1.3 KiB
C++
70 lines
1.3 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);
|
|
vector<int> spendings(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;
|
|
|
|
if(ng == 0){
|
|
continue;
|
|
}
|
|
|
|
vector<string> receivers(ng);
|
|
for(int j = 0; j < ng; ++i){
|
|
fin >> receivers[j];
|
|
}
|
|
|
|
if(money == 0){
|
|
continue;
|
|
}
|
|
|
|
int money_per_person = money / ng;
|
|
|
|
for(const string &receiver : receivers){
|
|
bank[names_to_index[receiver]] += money_per_person;
|
|
spendings[names_to_index[receiver]] -= money_per_person;
|
|
}
|
|
}
|
|
|
|
// Printing the output
|
|
for(int i = 0; i < np; ++i){
|
|
fout << index_to_name[i] << bank[i] - spendings[i] << endl;
|
|
}
|
|
|
|
return 0;
|
|
} |