Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <vector>
  4. #include <limits.h>
  5. #include <algorithm>
  6. #include <stack>
  7. #include <queue>
  8. #include <map>
  9. #include <cstring>
  10. #include <math.h>
  11. #define ll long long
  12. #define EPS 1e-9
  13. const int maxInt = 2147483647;
  14. const double PI = acos(-1);
  15. using namespace std;
  16. void readFromFile(){freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
  17. ll arr[100005];
  18. ll dp[100005];
  19. int main(int argc, char const *argv[])
  20. {
  21. int n,x;
  22. cin>>n;
  23. for (int i = 0; i < n; i++)
  24. {
  25. cin>>x;
  26. arr[x]++;
  27. }
  28. dp[0]=0;
  29. dp[1]=arr[1];
  30. for (int i = 2; i < 100005; i++)
  31. {
  32. dp[i]=max(dp[i-2]+i*arr[i],dp[i-1]);
  33. }
  34. cout<<dp[100004];
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement