456C codeforces - Boredom


456C codeforces - Boredom







Solution in C++


#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;
#define pii pair<int,int>

lli n,t,sol;
map<lli,lli> cnt,dp;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>t,
        cnt[t]+=t;
    for(int i=1;i<=100001;i++)dp[i]=max(dp[i-2]+cnt[i],dp[i-1]);
    cout<<dp[100000];
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق