分析:简单dp。。具体看代码。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1e5+5;
struct node
{
int x,p;
}a[N];
const int inf=2147483647;
int n;
int dp[1005][1005];
bool cmp1(node x,node y)
{
return x.x<y.x;
}
bool cmp2(node x,node y)
{
return x.x>y.x;
}
int main()
{
scanf("%d",&n);
fo(i,1,n)scanf("%d%d",&a[i].x,&a[i].p);
int ans=0;
sort(a+1,a+1+n,cmp1);
fo(cas,0,1)
{
fo(i,1,n)
{
int k=i,val=0;
fo(j,i+1,n)
{
while (k&&abs(a[j].x-a[i].x)>=abs(a[i].x-a[k].x))
{
val=max(val,dp[i][k]+a[i].p);
k--;
}
dp[j][i]=val;
}
}
fo(i,1,n)
fo(j,i+1,n)
{
ans=max(ans,dp[j][i]+a[j].p);
}
memset(dp,0,sizeof(dp));
sort(a+1,a+1+n,cmp2);
}
printf("%d\n",ans);
return 0;
}