Skip to content

Instantly share code, notes, and snippets.

@estelabn
Created September 29, 2023 01:46
Show Gist options
  • Save estelabn/1f90714a22259df121dad2ccb74dfdeb to your computer and use it in GitHub Desktop.
Save estelabn/1f90714a22259df121dad2ccb74dfdeb to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<pair<int,int>> aux,A;
for(int i=0; i<n; i++){
int a; cin >> a;
A.push_back({a,0});
aux.push_back({a,1});
}
for(int i=0; i<n; i++){
int b; cin >> b;
if(b > k) continue;
int a = A[i].first;
aux.push_back({0,1});
A[i].second = b;
int diff = k - b;
if(diff < 0) continue;
aux.push_back({diff + 1, -1});
if(b + a > k) continue;
aux.push_back({a, -1});
aux.push_back({diff + 1, 1});
}
sort(aux.begin(), aux.end());
int maior = 0;
int atual = 0;
int ant = -1;
for(auto [a,b]: aux){
if(a == ant) atual+= b;
else{
maior = max(maior, atual);
ant = a;
atual += b;
}
if(a > k){
cout << maior << endl;
return 0;
}
}
maior = max(maior, atual);
cout << maior << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment