64,654
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
int row;
cin>>row;
int limit,num,total,n;
string str;
while(row--)
{
map<string,int> bill;
cin>>limit;
cin>>num;
while(num--)
{
cin>>n;
cin>>total;
if( total > n * limit )
total = n*limit;
while(n--)
{
cin>>str;
pair<string,int> s(str,0);
bill.insert(s);
}
cin>>str;
map<string,int>::iterator map_it = bill.begin();
while( map_it != bill.end() )
{
if(map_it->first==str)
map_it->second+=total;
++map_it;
}
}
map<string,int>::iterator map_it = bill.begin();
while( map_it != bill.end() )
{
if( map_it->second != 0)
cout<<map_it->first<<" "<<map_it->second<<endl;
++map_it;
}
}
return 0;
}