#include #include #include #include #include #include using namespace std; const int g=(1<<5); const int g2=(1<<4)-1; long long int st[2][g]; const int now1=0; const int next1=1; struct E{ long long int x ,y,c; bool operator<(const E& e1)const{ if (x!=e1.x)return x s1; map ms; vector vec; int n; cin>>n; for(int i=0;i>e1.x>>e1.y>>e1.c; vec.push_back(e1); s1.insert(e1.y); } std::sort(vec.begin(),vec.end()); memset(st,0,sizeof(st)); long long int p=1; for(set::iterator it=s1.begin();it!=s1.end();it++){ ms[(*it)]=p; p++; } for(int i=0;i=oldP;j--){ E e2=vec[j]; long long int c=search(0,0,e2.y-1,0,g2,now1)+e2.c; update(c,0,e2.y,e2.y,0,g2,now1); } oldP=i; i--; x=e1.x; } } cout<