Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. int N, Q;
  2. cin >> N >> Q;
  3. int *array = new int[N];
  4. for (int i = 0; i < N; i++)
  5. {
  6. cin >> array[i];
  7. }
  8. sort(array, array + N);
  9.  
  10. int k = 0;
  11. int j = 0;
  12. for (int i = 0; i < N; i++)
  13. {
  14. if (array[N - i - 1] = Q)
  15. k++;
  16. else
  17. if (array[N - i - 1] < Q)
  18. {
  19. if ((N - i - 1) != j)
  20. {
  21. if (array[N - i - 1] + array[j] <= Q)
  22. {
  23. k++;
  24. j++;
  25. }
  26. else
  27. k++;
  28. }
  29. else
  30. k++;
  31. }
  32. }
  33. cout << k;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement