Test instructions: Give you a binary tree, point a bit of power, every time to the left or go to the right, to find the longest way to go, and point right and less than K;
Idea: The official solution, ruler take, my writing, two points on the tree,
For a chain, enumerate each point as the end point, vector the point to the root node prefix and, two minutes can be;
See Code;
Learn from the user code.
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <queue> #include <algorithm> #include <stack> #include <cstring> #include <vector> #include <list> #include <set> #include <map> using namespace
Std
#define LL Long Long #define PI (4*atan (1.0)) #define EPS 1e-4 #define BUG (x) cout<< "Bug" <<x<<endl;
const int n=1e6+10,m=1e6+10,inf=2147483647;
const LL inf=1e18+10,mod=2147493647;
Array size int n,ans,k,a[n];
vector<int>v;
void Dfs (int x) {int s=0,t=v.size ()-1;
int e=v.size () -1,ansq=-1;
while (s<=e) {int mid= (s+e) >>1;
if (v[t]-v[mid]<=k) {ansq=mid;
E=mid-1;
} else s=mid+1;
} if (v[t]<=k) Ans=max (ans,t+1);
else Ans=max (ANS,T-ANSQ);
int Z=v[v.size ()-1]; if (x*2<=n) {v.push_back (z+a[x<<1]);
DFS (X<<1);
V.pop_back ();
} if (x*2+1<=n) {v.push_back (z+a[x<<1|1]);
DFS (X<<1|1);
V.pop_back ();
}} int main () {int T;
scanf ("%d", &t);
while (t--) {ans=0;
V.clear ();
scanf ("%d%d", &n,&k);
for (int i=1;i<=n;i++) scanf ("%d", &a[i]);
V.push_back (a[1]);
DFS (1);
if (ans) printf ("%d\n", ans);
else printf (" -1\n");
} return 0; }