Advertisement
ibragimova_mariam

CF

Oct 2nd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<int> cnt(100001);
  6.  
  7. int main() {
  8. int n;
  9. cin >> n;
  10.  
  11. for(int i = 0; i < n; i++)
  12. {
  13. int a;
  14. cin >> a;
  15. cnt[a]++;
  16. }
  17.  
  18. int m = 100001;
  19.  
  20. vector<long long> d(m);
  21. d[0] = 0;
  22. d[1] = cnt[1];
  23. for(int i = 2; i < m; i++) {
  24. d[i] = max(d[i - 1], d[i - 2] + cnt[i] * i);
  25. }
  26. cout << d[m - 1];
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement