Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <map>
- using namespace std;
- int main(){
- int k, n;
- cin >> k >> n;
- int a[n];
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- int b[n];
- for(int i = 0; i < n; i++) {
- cin >> b[i];
- }
- sort(a, a + n);
- sort(b, b + n);
- long long answer = (long long)n * (long long)n;
- for(int i = 0; i < n; i++) {
- int fali = k - a[i];
- if(fali >= 0) {
- int indeks = upper_bound(b, b + n, fali - 1) - b;
- if(indeks >= 0 and indeks <= n) {
- answer -= indeks;
- }
- }
- }
- cout << answer << endl;
- return 0;
- }
- /*
- 5 * 5 = 25
- 25 - 1 = 24
- 7 5 3 4 2
- 4 3 2 2 1
- 4 - 2 = 2;
- 2, 3, 4, 5, 7
- 1, 2, 2, 3, 4
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement