fork download
  1. // BAI 3
  2.  
  3. #include "bits/stdc++.h"
  4. #define boostcode ios_base:: sync_with_stdio(0); cin.tie(0);
  5. #define openf freopen("input.inp", "r", stdin); freopen("output.out", "w", stdout);
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10.  
  11. int n, a, b;
  12. int c[1000001];
  13.  
  14. int temp;
  15. map<int, int> d;
  16. set<pair<bool, pair<int, int>>> quan;
  17. // b[i] = (k, m, x): (đã được bên Trắng lấy trước chưa, số quân còn lại, loại màu)
  18. bool turn; // 0 for white, 1 for black
  19. ll acount, bcount;
  20. ll res;
  21.  
  22. int main()
  23. {
  24. boostcode;
  25. //openf;
  26.  
  27. cin >> n >> a >> b;
  28.  
  29. for (int i = 0; i < n; i++) {
  30. cin >> temp;
  31. d[temp]++;
  32. }
  33.  
  34. for (auto it:d) {
  35. quan.insert(make_pair(0, make_pair(it.second, it.first)));
  36. }
  37. /*for (auto it:quan) {
  38.   cout << it.first << ' ' << it.second.first << ' ' << it.second.second << '\n';
  39.   }*/
  40. while (!quan.empty() && !(*quan.begin()).first) {
  41. auto it = quan.begin();
  42. bool k = (*it).first;
  43. int m = (*it).second.first;
  44. int x = (*it).second.second;
  45. //cout << k << ' ' << m << ' ' << x << '\n';
  46. m--;
  47. if (!turn) { // For white
  48. //cout << "WHITE!\n";
  49. if (!k) {
  50. k = true;
  51. acount++;
  52. }
  53. if (!m) {
  54. bcount++;
  55. }
  56. // Update values:
  57. quan.erase(it);
  58. if (m) {
  59. quan.insert(make_pair(k, make_pair(m, x)));
  60. }
  61. } else { // For black
  62. //cout << "BLACK!\n";
  63. // Update values:
  64. quan.erase(it);
  65. }
  66. //cout << k << ' ' << m << ' ' << x << '\n';
  67. //cout << '\n';
  68. turn = !turn;
  69. }
  70. while (!quan.empty()) {
  71. auto it = quan.begin();
  72. bool k = (*it).first;
  73. int m = (*it).second.first;
  74. int x = (*it).second.second;
  75. m--;
  76. if (!turn) { // For white
  77. if (!m) {
  78. bcount++;
  79. }
  80. // Update values:
  81. quan.erase(it);
  82. if (m) {
  83. quan.insert(make_pair(1, make_pair(m, x)));
  84. }
  85. } else { // For black
  86. quan.erase(it);
  87. }
  88. turn = !turn;
  89. }
  90.  
  91. //cout << acount << ' ' << bcount << '\n';
  92. cout << acount*a + b*bcount;
  93.  
  94. return 0;
  95. }
  96.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty