fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1000010;
  5.  
  6. int cnt[N];
  7. long long arr[N];
  8.  
  9. int main() {
  10. int n;
  11. cin>>n;
  12. memset(cnt, 0, sizeof(cnt));
  13. for (int i = 0; i < n; i++) {
  14. int foo;
  15. cin>>foo;
  16. cnt[foo]++;
  17. }
  18. arr[0] = 0;
  19. for (int i = 1; i < N; i++) {
  20. arr[i] = (long long)i * cnt[i];
  21. if (i - 2 >= 0) {
  22. arr[i] += arr[i - 2];
  23. }
  24. if (arr[i - 1] > arr[i]) {
  25. arr[i] = arr[i - 1];
  26. }
  27. }
  28. cout << arr[N - 1] << endl;
  29. return 0;
  30. }
Success #stdin #stdout 0s 26952KB
stdin
Standard input is empty
stdout
0