All pastes #331039 Raw Edit

Untitled

public cpp v1 · immutable
#331039 ·published 2007-01-28 14:15 UTC
rendered paste body
#include <iostream>#include <string>#include <vector>using namespace std;typedef pair<string, int> bar;int main(){	int _T; scanf("%d", &_T);	while(_T--) {		int N; string temp; vector<bar> inp; vector<int> foo; int t;		scanf("%d", &N); for(int i = 0 ; i < N ; ++i) {  cin >> temp >> t; inp.push_back(make_pair(temp, t)); }		int K; scanf("%d", &K);		for(int i = 0 ; i < K ; ++i) { scanf("%d", &t); foo.push_back(t-1); }		int max_val=-1, min_ind = -1;		for(int i = 0 ; i < K ; ++i) {			if(inp[foo[i]].second > max_val) {				max_val = inp[foo[i]].second;				min_ind = foo[i];			}		}		int penalty = 0;		for(int i = 0 ; i < K ; ++i) {			if(foo[i] != min_ind) penalty += inp[foo[i]].second;		}		cout << inp[min_ind].first << " " << penalty << endl;	}	return 0;}