#include #include #include #include #include #include #include #include #include #include #include #include #include #define max(x,y) ((x) > (y) ? (x) : (y)) #define min(x,y) ((x) < (y) ? (x) : (y)) using namespace std; int main(void) { while (1) { int n; string trademark; vector names; vector prices; vector actions; vector sellprices; map > sellers; vector buyprices; map > buyers; cin >> n >> trademark; if (n == 0) break; for (int i=0; i> name >> action >> price; names.push_back(name); prices.push_back(price); actions.push_back(action); if (action == "sell") { sellprices.push_back(price); if (sellers.find(price) == sellers.end()) { sellers[price] = vector(); } sellers[price].push_back(i); } else /*if (action == "buy")*/ { buyprices.push_back(price); if (buyers.find(price) == buyers.end()) { buyers[price] = vector(); } buyers[price].push_back(i); } } sort(sellprices.begin(), sellprices.end()); sort(buyprices.begin(), buyprices.end()); cout << trademark << endl; int len = names.size(); for (int i=0; i toout; for (int j=buyprices.size()-1; (j>=0 )&&( buyprices[j]>=prices[i]); --j) { for (vector::iterator k = buyers[buyprices[j]].begin(); k != buyers[buyprices[j]].end(); ++k) { toout.push_back(*k); } } if (toout.size() == 0) { cout << " NO-ONE"; } else { sort(toout.begin(), toout.end()); for (vector::iterator k = toout.begin(); k != toout.end(); ++k) { cout << " " << names[*k]; } } cout << endl; } else { vector toout; int lb = sellprices.size(); for (int j=0; (j::iterator k = sellers[sellprices[j]].begin(); k != sellers[sellprices[j]].end(); ++k) { toout.push_back(*k); } } if (toout.size() == 0) { cout << " NO-ONE"; } else { sort(toout.begin(), toout.end()); for (vector::iterator k = toout.begin(); k != toout.end(); ++k) { cout << " " << names[*k]; } } cout << endl; } } } return 0; }