Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void qs_helper(int* A, int l, int r)
- {
- if (r > l)
- {
- int i = 0, j, k, pe;
- int m = (l + r) / 2;
- if (A[l] < A[m])
- if (A[m] < A[r])
- swap(A[l], A[m]);
- else
- if (A[l] < A[r])
- swap(A[l], A[r]);
- else
- if (A[r] < A[m])
- swap(A[l], A[m]);
- else
- if (A[r] < A[l])
- swap(A[l], A[r]);
- pe = A[i]; i = l; j = l + 1; k = r;
- while (j <= k)
- if (A[j] == pe)
- j++;
- else
- if (A[j] < pe)
- {
- swap(A[i], A[j]);
- i++; j++;
- }
- else
- {
- swap(A[j], A[k]);
- k--;
- }
- }
- }
- void quick_sort(int* A, int n)
- {
- qs_helper(A, 0, n - 1);
- }
- int main()
- {
- int n;
- cin >> n;
- int t;
- cin >> t;
- int* a = new int[n];
- for (int i = 0; i < n; i++)
- cin >> a[i];
- quick_sort(a, n);
- int i = 0;
- int j = n - 1;
- int res = 0;
- while (i < j)
- {
- if (a[i] + a[j] > t)
- j--;
- if (a[i] + a[j] < t)
- i++;
- else
- {
- res++;
- i++;
- j--;
- }
- }
- cout << res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement