Sunday, August 17, 2014

uva :119 - Greedy Gift Givers


#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    int n,y=0;
    while(scanf("%d",&n)==1)
    {
        if(y>0)printf("\n");
        y=100;
        string name[n],s;
        int account[n],m,b,l;
        map<string,int>w;
        for(int i=0;i<n;i++)
        {
            cin >> name[i];
            w[name[i]]=i;
            account[i]=0;
        }
        for(int i=0;i<n;i++)
        {
            cin >> s >> b >> m;
            int p=w[s];
            if(m==0)continue;
            account[p]=account[p]+b%m-b;
            for(int j=0;j<m;j++)
            {
                cin >> s;
                p=w[s];
                account[p]=account[p]+b/m;
            }
        }
        for(int i=0;i<n;i++)
        cout << name[i] << " "<<account[i]<< endl;
    }
    return 0;
}

No comments:

Post a Comment