Created
September 29, 2023 01:46
-
-
Save estelabn/1f90714a22259df121dad2ccb74dfdeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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