题面
#include<bits/stdc++.h>
#define N 5009
using namespace std;
void file() {
freopen("robber.in","r",stdin);
freopen("robber.out","w",stdout);
}
inline int read() {
int x=0,y=0;
char c=getchar();
while(!isdigit(c)) y|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return y?-x:x;
}
inline void write(int x) {
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar('0'+x%10);
}
struct robber {
int a,b,c;
} rb[N];
bool cmp(const robber&x,const robber&y) {
return x.c>y.c;
}
int n,matched[N];
bool match(int i,int l,int r) {
if(l>r) return 0;
int j=matched[l];
if(!j) {
matched[l]=i;
return 1;
}
if(rb[i].b<rb[j].b) {
if(match(j,l+1,rb[j].b)) {
matched[l]=i;
return 1;
} else return 0;
} else {
return match(i,l+1,r);
}
}
int main() {
file();
n=read();
for(int i=1; i<=n; ++i) rb[i].a=read(),rb[i].b=read()-1,rb[i].c=read();
sort(rb+1,rb+1+n,cmp);
int ans=0;
for(int i=1; i<=n; ++i)
if(match(i,rb[i].a,rb[i].b))
ans+=rb[i].c;
write(ans),putchar('\n');
return 0;
}