题目1014:排名
///
/// 有bug。。一直AC不了,求大佬指教
///
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
bool cmp(pair<string, int> a, pair<string, int> b)
{
if(a.second != b.second){
return a.second > b.second;
}else {
return a.first < b.first;
}
}
int main() {
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int N, M, GradeLine;
while(scanf("%d",&N) != EOF) {
if(N == 0){
break;
}
scanf("%d %d",&M, &GradeLine);
vector<int> Grade;
map<string, int> mapp;
for(int i = 0; i < M; i++){
int temp;
cin >> temp;
Grade.push_back(temp);
}
int K = 0;
for(int i = 0; i < N; i++){
string str;
int temp, ans = 0;
cin >> str >> temp;
for(int i = 0; i < temp; i++){
int T;
cin >> T;
ans += Grade[T - 1];
}
if(ans >= GradeLine){
mapp[str] = ans;
K++;
}
}
cout << mapp.size() << endl;
vector<pair<string, int> > v(mapp.begin(), mapp.end());
sort(v.begin(), v.end(), cmp);
vector<pair<string, int> >::iterator iter;
for(iter = v.begin(); iter != v.end(); iter++){
cout << iter -> first << " " << iter -> second << endl;
}
}
return 0;
}