Skip to content

Instantly share code, notes, and snippets.

@joaogui1
Created April 18, 2016 22:55
Show Gist options
  • Save joaogui1/cc83e65f2258d4c8f0991c96c47be081 to your computer and use it in GitHub Desktop.
Save joaogui1/cc83e65f2258d4c8f0991c96c47be081 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1010
pair <int,int> pi[MAXN];
int dp[MAXN][3610];
int n;
int solve(int atual, int tempo){
if(atual >= n)return 0;
if(dp[atual][tempo] >= 0)return dp[atual][tempo];
int davez = 0, prox = 0;
prox = solve(atual+1,tempo);
if(pi[atual].second >= tempo)
davez = pi[atual].first - pi[atual].second + solve(atual+1,pi[atual].first);
return dp[atual][tempo] = max(davez,prox);
}
int main(){
scanf("%d", &n);
memset(dp,-1,sizeof(dp));
for(int p = 0; p < n; p++){
int i,j;
scanf("%d %d", &i, &j);
pi[p].first = j, pi[p].second = i;
}
sort(pi,pi+n);
printf("%d\n",solve(0,0));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment