Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DP practice
- // 455A --- codeforces
- #include <iostream>
- #include <stdio.h>
- #include <cstring>
- using namespace std;
- const int N = 1000010;
- long long int dp[N];
- long long int cnt[N];
- int main()
- {
- int iT;
- int iNum,iLarge;
- int i,j;
- cin >> iT;
- memset(cnt,0,sizeof(cnt));
- iLarge = 0;
- for ( i=0 ; i<iT ; i++ )
- {
- cin >> iNum;
- // count number appear times
- cnt [iNum]++;
- // store the largest number to reduce run time
- if ( iNum>iLarge )
- iLarge = iNum;
- }
- dp[0] = 0;
- dp[1] = cnt[1];
- for ( j=2 ; j<=iLarge ; j++ )
- dp[j] = max(dp[j-1],dp[j-2] + (cnt[j]*j));
- cout << dp[j-1] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement