MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Two Platforms/solution.cpp:73–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71vl x;
72ll mar[300000];
73int main()
74{
75 IOS
76 cin>>t;
77 while(t--)
78 {
79 cin>>n>>k;
80 x.clear();
81 REP(i,n)
82 {
83 cin>>xi;
84 x.pb(xi);
85 }
86 REP(i,n) cin>>yi;
87 sort(all(x));
88 ll ans=0;
89 mar[n-1]=1;
90 for(int i=n-2;i>=0;i--)
91 {
92 mar[i] = max(mar[i+1],upper_bound(all(x), x[i]+k)-(x.begin()+i));
93 }
94
95 REP(i,n)
96 {
97 ll ind = upper_bound(all(x),x[i]+k)-x.begin();
98 if(ind==n)
99 {
100 ans = max(ans, ind-i);
101 }
102 else
103 ans = max(ans, ind-i+mar[ind]);
104 }
105 cout<<ans<<endl;
106 }
107}

Callers

nothing calls this directly

Calls 2

REPFunction · 0.85
maxFunction · 0.85

Tested by

no test coverage detected