Skip to content

Instantly share code, notes, and snippets.

@philopaterwaheed
Created February 4, 2024 02:54
Show Gist options
  • Save philopaterwaheed/44011c9fee857f73ad2ea0c60521d205 to your computer and use it in GitHub Desktop.
Save philopaterwaheed/44011c9fee857f73ad2ea0c60521d205 to your computer and use it in GitHub Desktop.
Apartments CSES solving code https://cses.fi/problemset/task/1084
while (t--)
{
int out = 0 , last = 0 ;
dec (int , n , m , k );
array(int , dis , n );
array(int , size , m);
std :: sort (dis.begin() , dis.end());
std :: sort (size.begin() , size.end());
int ptr1 = 0 , ptr2 = 0 ;
while (ptr2 < m && ptr1 < n) {
{
//std :: cout << dis[ptr1] << " " << size [ptr2] << "\n";
if (std :: abs (dis[ptr1] - size [ptr2]) <= k )
{
ptr1 ++ ;
ptr2 ++ ;
out ++ ;
}
else {
if (dis[ptr1 ] < size[ptr2])
ptr1++;
else
ptr2 ++ ;
}
}
}
p(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment