I am moving from python to c++ and am facing some issues. In this recent Atcoder Beginner problem, I am getting TLE.
My solution
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for(int i=0; i<n; i++)
const int p = 5;
ll dp[100001][p];
ll helper(ll time, ll pos, map<pair<ll, ll>, ll> &snuke){
if (time > 10|| pos < 0 || pos > 4) return 0;
if (dp[time][pos] != 0) return dp[time][pos];
ll first, second, third;
first = helper(time+1, pos-1, snuke);
second = helper(time+1, pos+1, snuke);
third = helper(time+1, pos, snuke);
ll ans = max(first, second);
ans = max(ans, third);
dp[time][pos] = ans;
if (snuke.count(make_pair(time, pos)) != 0)
dp[time][pos] += snuke[{time, pos}];
return dp[time][pos];
}
void solve(){
int n;
cin >> n;
map<pair<ll, ll>, ll> snuke;
forn(i, n){
ll t, x, a;
cin >> t >> x >> a;
snuke.insert(make_pair(make_pair(t, x), a));
}
cout << helper(0, 0, snuke);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
}