# Removed Interval

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1703    Accepted Submission(s): 558

Problem Description
Given a sequence of numbers

Input
The first line of input contains a number

Output
For each test case, output a single line consisting of “Case #X: Y”.

Sample Input
2 5 2 1 2 3 4 5 5 3 5 4 3 2 1

Sample Output
Case #1: 3 Case #2: 1

Source

 1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<map>
7 #include<queue>
8 #include<stack>
9 #include<vector>
10 #include<bitset>
11 #include<set>
12 #define ll __int64
13 #define mod 100000000
14 #define N 5e6+10
15 #define M 1e
16 using namespace std;
17 int t;
18 int n,l;
19 int a,b;
20 int dp;
21 int ans;
22 int main()
23 {
24     scanf("%d",&t);
25     for(int i=1;i<=t;i++)
26     {
27         scanf("%d %d",&n,&l);
28         a=0;
29         for(int j=1;j<=n;j++){
30             scanf("%d",&a[j]);
31             b[j]=-a[j];
32         }
33         int exm=1;
34         ans[exm]=a;
35         dp=1;
36         for(int j=2;j<=n;j++)
37         {
38             if(a[j]>ans[exm]){
39                 exm++;
40                 ans[exm]=a[j];
41                 dp[j]=exm;
42             }
43             else
44             {
45                 int pos=lower_bound(ans+1,ans+exm,a[j])-ans;
46                 ans[pos]=a[j];
47                 dp[j]=pos;
48             }
49         }
50         int an=0;
51         for(int j=0;j<=n;j++)
52            ans[j]=1e9;
53         int re=0;
54         for(int j=n-l;j>=1;j--)
55         {
56             int x=lower_bound(ans,ans+n,b[j])-ans;//
57             an=max(an,dp[j]+x);
58             int y=lower_bound(ans,ans+n,b[j+l])-ans;
59             ans[y]=b[j+l];
60             re=max(re,y+1);
61         }
62        printf("Case #%d: %d\n",i,max(an,re));
63     }
64     return 0;
65 }
66 /*
67 6
68 6 2
69 1 3 5 7 2 4
70 */