Naxocist

Majority

Apr 1st, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endll '\n'
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.     int n; cin >> n;
  8.  
  9.     int criteria = n/2;
  10.  
  11.     map<int, int> mp;
  12.  
  13.     for(int i=0; i<n; ++i){
  14.         int x; cin >> x;
  15.         mp[x] += 1;
  16.     }
  17.  
  18.     int mx = -1e9, w;
  19.  
  20.     for(auto k : mp){
  21.         if(k.second > criteria) {
  22.             if(k.second > mx){
  23.                 mx = k.second;
  24.                 w = k.first;
  25.             }
  26.         }
  27.     }
  28.  
  29.     if(mx < 0){
  30.         cout << "no";
  31.         return 0;
  32.     }
  33.     cout << w;
  34.  
  35.     return 0;
  36. }
  37.  
  38. // I'll make eggs, chips and drinks.
Advertisement
Add Comment
Please, Sign In to add comment