luogu_1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

#include <cstdio>
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
map<string,int> m;
int n,a[20];
string s[20];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        cin>>s[i];
        m[s[i]]=i;
    }
    for(int i=1;i<=n;i++){
        string s1;
        cin>>s1;
        int all,sum;
        scanf("%d%d",&all,&sum);
        a[m[s1]]-=all;
        if(sum)a[m[s1]]+=all%sum;
        if(sum)all/=sum;
        while(sum--){
            string s2;
            cin>>s2;
            a[m[s2]]+=all;
        }
    }
    for(int i=1;i<=n;i++)cout<<s[i]<<' '<<a[i]<<endl;
    return 0;
}

  

posted @ 2017-10-10 21:31  wqtnb_tql_qwq_%%%  阅读(116)  评论(0编辑  收藏  举报