Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main() {
- 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());
- sort(b.begin(), b.end());
- long long result = 0;
- for(int i = 0; i < n; i++) {
- int x = k - a[i];
- int L = 0, R = n;
- while(L < R) {
- int middle = L + (R - L) / 2;
- if(x <= b[middle]) {
- R = middle;
- }
- else {
- L = middle + 1;
- }
- }
- if(L < n and b[L] < x) {
- L++;
- }
- if(b[L] >= x) {
- result += (n - L);
- }
- }
- cout << result << endl;
- return 0;
- }
- // 2 2 3 3 4 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement