fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. #define in(i,a,n) for(i=0;i<n;i++)cin>>a[i];
  4. #define M2 1000000007
  5. #define sz(c) c.size()
  6. #define fr first
  7. #define sc second
  8. #define pb push_back
  9. #define ppb pop_back
  10. #define mp make_pair
  11. #define all(a) (a).begin(),(a).end()
  12. #define rep(i,a,n) for(int i=a ; i<n ; i++)
  13. #define what_is(x) cout << x << " is " << x << endl;
  14. #define r0 return 0;
  15. #define U 998244353
  16. #define pi 3.1415926536
  17. #define px cout<<x<<"\n";
  18. #define M1 998244353
  19. #define so cout<<"test ";
  20. #define vl vector<ll>
  21. #include<cmath>
  22. using namespace std;
  23. vl a,b;ll m1[1000007];
  24. map<pair<ll,ll>,ll>dp,used;
  25. ll island(ll cr,ll lt,ll n)
  26. {
  27. if(used[{cr,lt}]!=0)
  28. return dp[{cr,lt}];
  29. if(lt<1)return 0;
  30. ll u=0,v=0,w=0;
  31. if(cr>n)
  32. return 0;
  33. if(lt>1)
  34. u=island(cr+lt-1,lt-1,n);
  35. if(lt!=0)v=island(cr+lt,lt,n);
  36. w=island(cr+lt+1,lt+1,n);
  37. dp[{cr,lt}]=(m1[cr])+max(u,max(v,w));
  38. used[{cr,lt}]=1;
  39. return dp[{cr,lt}];}
  40. main()
  41. {ll i,j=0,k=0,l=0,n,m,ta,tb,t=0,u,h;
  42. ll q;
  43. scanf("%I64d%I64d",&n,&k);
  44. ll a[n];
  45. rep(i,0,n){scanf("%I64d",&a[i]);m1[a[i]]++;}
  46. cout<<island(k,k,a[n-1]);}
  47.  
Runtime error #stdin #stdout 0s 4408KB
stdin
8 8
9
19
28
36
45
55
66
78
stdout
Standard output is empty