fork download
  1. /*
  2. وَلا تَقولَنَّ لِشَيءٍ إِنّي فاعِلٌ ذلِكَ غَدًا۝إِلّا أَن يَشاءَ اللَّهُ وَاذكُر رَبَّكَ إِذا نَسيتَ وَقُل عَسى أَن يَهدِيَنِ رَبّي لِأَقرَبَ مِن هذا رَشَدًا
  3. */
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. // #define int long long
  7. #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  8. #define lp(i, x, n) for (int(i) = (x); (i) < (n); (i)++)
  9. #define sz(x) x.size()
  10. #define all(x) x.begin(), x.end()
  11. #define rall(x) x.rbegin(), x.rend()
  12. #define en "\n"
  13. #define TEST \
  14. int t; \
  15. cin >> t; \
  16. while (t--)
  17. #define in(X) \
  18. for (auto &it : (X)) \
  19. cin >> it
  20. #define out(X, n) \
  21. for (auto &it : (X)) \
  22. cout << it << n
  23. typedef long long ll;
  24. typedef vector<int> vi;
  25. typedef vector<long long> vll;
  26. typedef vector<vector<int>> vvi;
  27. typedef pair<int, int> pii;
  28. typedef vector<pair<int, int>> vpii;
  29. const long double PI = acos(-1.0L); // or double PI =3.141592653589793238;
  30. const int mod = 1e9 + 7;
  31. const ll OO = LLONG_MAX;
  32. const int oo = 0x7f7f7f7f;
  33. int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
  34. int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
  35. int dx[] = {-1, 0, 0, 1};
  36. int dy[] = {0, -1, 1, 0};
  37.  
  38. void NeedForSpeed()
  39. {
  40. ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  41. #ifndef ONLINE_JUDGE
  42. freopen("input.txt", "r", stdin);
  43. freopen("output.txt", "w", stdout);
  44. #endif
  45. }
  46. /*
  47. ╭━━━╮╱╱╭╮
  48. ╰╮╭╮┃╱╱┃┃
  49. ╱┃┃┃┃╭╮┃╰━╮╭━━╮
  50. ╱┃┃┃┃┣┫┃╭╮┃┃╭╮┃
  51. ╭╯╰╯┃┃┃┃╰╯┃┃╰╯┃
  52. ╰━━━╯╰╯╰━━╯╰━━╯
  53. */
  54.  
  55. /*{وَمَن يَتَّقِ اللَّهَ يَجْعَل لَّهُ مَخْرَجًا}*/
  56. void XD()
  57. {
  58. /* استعن بالله ACPC*/
  59. int n, m, x, y, o;
  60. char q;
  61. cin >> n >> m;
  62. o = m;
  63. map<int, int> b, s;
  64. lp(i, 0, n)
  65. {
  66. cin >> q >> x >> y;
  67. if (q == 'B')
  68. {
  69. b[x] += y;
  70. }
  71. else
  72. {
  73. s[x] += y;
  74. }
  75. }
  76. vector<pair<int, int>> ss;
  77. for (auto it = s.begin(); it != s.end() && m; it++, m--)
  78. {
  79. ss.push_back({it->first, it->second});
  80. }
  81. while (!(ss.empty()))
  82. {
  83. cout << "S " << ss.back().first << " " << ss.back().second << en;
  84. ss.pop_back();
  85. }
  86. for (auto it = b.rbegin(); it != b.rend() && o; it++, o--)
  87. {
  88. cout << "B " << it->first << " " << it->second << en;
  89. }
  90. }
  91. // مر أعربي علي قوم فقال
  92. int32_t main()
  93. {
  94. // اذكر الله
  95. NeedForSpeed();
  96. // TEST
  97. XD();
  98. }
  99.  
  100. /*
  101. cout << fixed << setprecision(9);
  102. */
Success #stdin #stdout 0.01s 5336KB
stdin
6 2
B 10 3
S 50 2
S 40 1
S 50 6
B 20 4
B 25 10
stdout
S 50 8
S 40 1
B 25 10
B 20 4