#include #include using namespace std; const int maxs = 300; int c,g[1010][maxs*2+1],l[1010],s[1010],p[1010],r[100010]; void just() { int n = 0; for (int i=0;iv;j--) g[i][j] = g[i][j-1]; s[i]++; } void ins(int x) { if (c == 0){ g[0][0] = l[0] = x; s[0] = 1; p[0] = 0; c = 1; return; } int i = lower_bound(l, l + c, x) - l; if (i == c) i--; x -= p[i]; int v = lower_bound(g[i], g[i] + s[i], x) - g[i]; mak(i, v); g[i][v] = x; if (s[i] == maxs * 2) just(); else if (s[i] == v + 1) l[i] = x + p[i]; } int main() { int N; scanf ("%d",&N); while (N--){ int x,y; scanf ("%d %d",&x,&y); rem(y); add(x,y); ins(x); } int ans = 0; for (int i=0;i