Description
对于 30%数据: 1 ≤ n ≤ 100
对于 100%数据: 1 ≤ n ≤ 100000, 0 ≤ m ≤ 500000, 0 ≤ Pi, Vi ≤ 1000
Solution
看到这么随意的数据范围可以推断是水题
可以把第一列看做x坐标第二列看做y坐标,价值就是点权,可以发现这是一个二维偏序问题,直接排序然后树状数组
需要注意的是可能出现第一维相同的情况,这个时候按照x相同时y降序即可
Code
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define drp(i,st,ed) for (int i=st;i>=ed;--i)
#define lowbit(x) ((x)&(-(x)))
const int INF=2000000000;
const int N=200005;
const int E=1000005;
struct edge {int x,y;} e[E];
int a[N],b[N];
int c[N],n;
bool cmp(edge a,edge b) {
return a.x<b.x||a.x==b.x&&a.y>b.y;
}
void ins(int x,int v) {
while (x<=n) {
c[x]=std:: max(c[x],v);
x+=lowbit(x);
}
}
int ask(int x) {
int ret=0;
while (x) {
ret=std:: max(ret,c[x]);
x-=lowbit(x);
}
return ret;
}
int main(void) {
int m; scanf("%d%d",&n,&m);
rep(i,1,m) {
int x,y; scanf("%d%d",&x,&y);
e[i]=(edge) {x,y};
}
rep(i,1,n) scanf("%d",&b[i]);
rep(i,1,n) scanf("%d",&a[i]);
std:: sort(e+1,e+m+1,cmp);
int ans=0;
rep(i,1,m) {
int tmp=ask(e[i].y-1);
ans=std:: max(ans,tmp+a[e[i].x]+b[e[i].y]);
ins(e[i].y,tmp+a[e[i].x]+b[e[i].y]);
}
printf("%d\n", ans);
return 0;
}