mertozel's blog

By mertozel, history, 2 months ago, In English

Problem Link

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> dp;
map<int,int> mp;
const int mx = 1e5;
int n;

int solver(int range, int sum) {
    if(dp[range] != -1) return dp[range] = max(dp[range], sum);
    if(range > 1e5) return dp[range] = sum;
    if(range == mx) return dp[range] = sum + range * mp[range];
    return dp[range] = max(solver(range+2, sum + (range*mp[range])), solver(range+3, sum + ((range+1)*mp[range+1])));

int main() {
    int temp;
    for(int i = 0; i<n; i++) {
    return 0;

It gives error on Testcase 9. I have no idea about what I'm doing wrong.

Idea of the code is simple. Iterate through 1 to 1e5. Take max(i, i+1).

I'd be glad if you help me. Thanks in advance.

  • Vote: I like it
  • 0
  • Vote: I do not like it

2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

You can retype the vector and map it into long long.