AcWing 4951. 整理账本___显而易见的map
原题链接
中等
作者:
编号002
,
2024-04-08 16:10:08
,
所有人可见
,
阅读 2
#include<iostream>
#include<map>
using namespace std;
map<int, int> B, S;
int main()
{
int n, m, t;
cin >> n >> m;
char op;
int x, y;
while (n--)
{
cin >> op >> x >> y;
if (op == 'B') B[x] += y;
else S[x] += y;
}
if(S.size())
{
t = m;
auto it = S.begin();
while (t--)
{
it++;
if(it==S.end())break;
}
t = m;
while (t--)
{
it--;
cout << 'S' << ' ' << it->first << ' ' << it->second << endl;
if(it==S.begin())break;
}
}
if(B.size())
{
t = m;
auto it = B.end();
while (t--)
{
it--;
cout << 'B' << ' ' << it->first << ' ' << it->second << endl;
if(it==B.begin())break;
}
}
return 0;
}