Advertisement
LEGEND2004

G - Picking Numbers

Sep 7th, 2023
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. const int N = 1e5 + 5;
  6. const int mod = 1e18 + 7;
  7. const int INF = 1e18;
  8. int dp[N];
  9. int from[N];
  10. int a[N];
  11.  
  12. signed main()
  13. {
  14.     int n;
  15.     cin >> n;
  16.     map<int , int> cnt;
  17.     for(int i = 0; i < n; i++){
  18.         cin >> a[i];
  19.         cnt[a[i]]++;
  20.     }
  21.     int ans = 1;
  22.     for(int i = 0; i < n; i++){
  23.         ans = max(ans , cnt[a[i]] + cnt[a[i] + 1]);
  24.     }
  25.     cout << ans << endl;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement