Untitled
unknown
c_cpp
5 years ago
761 B
7
Indexable
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
int k, n;
cin >> k >> n;
vector<int> a(n), b(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end()); // gi podreduva broevite vo rastecki redosled
sort(b.begin(), b.end()); // gi podreduva broevite vo rastecki redosled
long long result = 0;
for(int i = 0; i < n; i++) {
int fali = k - a[i];
int indeks = lower_bound(b.begin(), b.end(), fali) - b.begin();
if(indeks >= 0 and indeks < n) {
result += (n - indeks);
}
}
cout << result << endl;
return 0;
}
Editor is loading...