?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
75532685 |
Practice: bhatt01tapasvi |
455A - 35 | C++17 (GCC 7-32) | Wrong answer on test 42 | 140 ms | 1184 KB | 2020-04-05 07:16:00 | 2020-04-05 07:16:00 |
#include<bits/stdc++.h> #define ll long long #define pb push_back #define rep(i,a,b) for(int i = a; i <= b; i++) #define mod 1000000007 #define mx 100003 #define ss second #define ff first #define ld long double #define pii pair<int, int> #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; unsigned long long int dp[mx]; int arr[mx]={0}; int main() { memset(dp,-1,sizeof(dp)); int n,temp; cin >> n; for(int i=0; i<n; i++) { cin >> temp; arr[temp]++; } dp[1]=arr[1]; dp[0]=0; for(int i=2; i<100001; i++) { dp[i]=max(dp[i-1],dp[i-2]+arr[i]*i); } cout << dp[100000] << endl; }
?
?
?
?