Advertisement
Guest User

Untitled

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