fork(2) download
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<algorithm>
  4. typedef long long ll;
  5. struct order{
  6. char ch;
  7. ll p,q;
  8. };
  9. bool sorting(order a,order b)
  10. {
  11. return a.p>b.p;
  12. }
  13. int main()
  14. {
  15. using namespace std;
  16. ll n,s5,i=0,b1=0,s1=0,countb=0,counts=0,f1=0,f2=0;
  17. struct order ar[1005],b[1005],s[1005],fb[1005],fs[1005];
  18. scanf("%lld%lld",&n,&s5);
  19. while(n--)
  20. {
  21. cin>>ar[i].ch>>ar[i].p>>ar[i].q;
  22. if(ar[i].ch=='B')
  23. {
  24. b[b1].ch='B';
  25. b[b1].p=ar[i].p;
  26. b[b1].q=ar[i].q;
  27. b1++;
  28. }
  29. else
  30. {
  31. s[s1].ch='S';
  32. s[s1].p=ar[i].p;
  33. s[s1].q=ar[i].q;
  34. s1++;
  35. }
  36. i++;
  37. }
  38. sort(b,b+b1,sorting);
  39. sort(s,s+s1,sorting);
  40. for(i=1;i<=b1;i++)
  41. {
  42. if(b[i].p==b[i-1].p)
  43. {
  44. b[i].ch='B';
  45. b[i].p=b[i].p;
  46. b[i].q=b[i].q+b[i-1].q;
  47. }
  48. else
  49. {
  50. fb[f1].ch='B';
  51. fb[f1].p=b[i-1].p;
  52. fb[f1].q=b[i-1].q;
  53. countb++;
  54. f1++;
  55. }
  56. }
  57. for(i=1;i<=s1;i++)
  58. {
  59. if(s[i].p==s[i-1].p)
  60. {
  61. s[i].ch='S';
  62. s[i].p=s[i].p;
  63. s[i].q=s[i].q+s[i-1].q;
  64. }
  65. else
  66. {
  67. fs[f2].ch='S';
  68. fs[f2].p=s[i-1].p;
  69. fs[f2].q=s[i-1].q;
  70. counts++;
  71. f2++;
  72. }
  73. }
  74. if(f2>s5)
  75. {
  76. for(i=0;i<s5;i++)
  77. {
  78. cout<<fs[i].ch<<" "<<fs[i].p<<" "<<fs[i].q;
  79. printf("\n");
  80. }
  81. }
  82. else
  83. {
  84. for(i=0;i<f2;i++)
  85. {
  86. cout<<fs[i].ch<<" "<<fs[i].p<<" "<<fs[i].q;
  87. printf("\n");
  88. }
  89. }
  90. if(f1>s5)
  91. {
  92. for(i=0;i<s5;i++)
  93. {
  94. cout<<fb[i].ch<<" "<<fb[i].p<<" "<<fb[i].q;
  95. printf("\n");
  96. }
  97. }
  98. else
  99. {
  100. for(i=0;i<f1;i++)
  101. {
  102. cout<<fb[i].ch<<" "<<fb[i].p<<" "<<fb[i].q;
  103. printf("\n");
  104. }
  105. }
  106. return 0;
  107. }
Success #stdin #stdout 0s 3444KB
stdin
Standard input is empty
stdout
Standard output is empty