Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save znxkznxk1030/2a0f96165c67834cb6f015fc662f5eb6 to your computer and use it in GitHub Desktop.
Save znxkznxk1030/2a0f96165c67834cb6f015fc662f5eb6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <iostream>
#include <stack>
#include <cstring>
#define ll long long int
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN(a,b) (a)>(b)?(b):(a)
#define pii pair<int , int>
#define time first
#define cost second
using namespace std;
pii sch[123];
int dp[123];
int n;
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int a, b;
scanf("%d %d", &a, &b);
sch[i] = pii(a, b);
}
int ans = 0;
for (int i = 1; i <= n + 1; i++)
{
for (int j = 1; j <= 5; j++)
{
int prev = i - j;
if (sch[prev].time == j)
dp[i] = MAX(dp[i], dp[prev] + sch[prev].cost);
else dp[i] = MAX(dp[prev], dp[i]);
}
}
printf("%d\n", dp[n + 1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment