ans

zhaocong 2022-04-03 13:34:01 26 返回题目

#include<bits/stdc++.h>

using namespace std;

int n,dp[30010],n2,maxx;

struct node{

int p,k;

}t[10010];

bool cmp(node a,node b){

return a.k<b.k;

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++){

	scanf("%d%d",&t[i].p,&t[i].k);

	maxx=max(maxx,t[i].k);

}

sort(t+1,t+n+1,cmp);

for(int i=1;i<=n;i++) for(int j=maxx;j>=t[i].k;j--) dp[j]=max(dp[j],dp[t[i].p]+t[i].k-t[i].p);

printf("%d",dp[maxx]);

return 0;

}

{{ vote && vote.total.up }}