fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //kaushik-04-12-2025
  5. int main() {
  6. cout<<"enter virus size ";
  7. int n;
  8. cin>>n;
  9. cout<<"enter vector a ";
  10. vector<int>a(n);
  11. vector<int>b(n);
  12. cout<<"enter vector b";
  13. for(int i = 0 ; i< n ;i++){
  14. cin>>a[i];
  15. }
  16. for(int i = 0 ; i< n ;i++){
  17. cin>>b[i];
  18. }
  19.  
  20. int goodbond=0, badbond=0;
  21. unordered_map<int,int>mp1;
  22. vector<pair<int,int>>goodvector;
  23.  
  24. priority_queue<pair<int,int>>pq;
  25.  
  26. for(int i = 0 ;i < n;i++){
  27. if(a[i] == b[i]){
  28. badbond++;
  29. mp1[a[i]]++;
  30. }
  31. else{
  32. goodbond++;
  33. goodvector.push_back({a[i],b[i]});
  34. }
  35. }
  36.  
  37. for(auto i : mp1){
  38. int type = i.first;
  39. int count = i.second;
  40. pq.push({count,type});
  41. }
  42.  
  43. while(pq.size() > 1){ // FIXED CONDITION
  44. auto t = pq.top(); pq.pop();
  45. int x = t.first;
  46. int y = t.second;
  47.  
  48. auto t2 = pq.top(); pq.pop(); // RENAME VARIABLE
  49. int x1 = t2.first;
  50. int y1 = t2.second;
  51.  
  52. pq.push({x - x1, y});
  53. }
  54.  
  55.  
  56. if(pq.empty()){
  57. cout<<"All bad bond have been resolved"<<endl;
  58. return 0;
  59. }
  60.  
  61. auto t = pq.top();
  62. int x = t.first;
  63. int y = t.second;
  64.  
  65. if(x == 0){
  66. cout<<"All bad bond have been resolved"<<endl;
  67. return 0;
  68. }
  69.  
  70. for(auto i : goodvector){
  71. int gooda = i.first;
  72. int goodb = i.second;
  73.  
  74. if(y != gooda && y != goodb){
  75. x--;
  76. }
  77. if(x == 0){
  78. cout<<"All bad bond have been resolved"<<endl;
  79. return 0;
  80. }
  81. }
  82.  
  83. cout<<"All bad bond cannot have been resolved"<<endl;
  84. return 0;
  85. }
  86.  
Success #stdin #stdout 0.01s 5316KB
stdin
5
1 1 1 1 1
1 1  1 2 1
stdout
enter virus size enter vector a enter vector bAll bad bond cannot have been resolved