Advertisement
Josif_tepe

Untitled

Jun 25th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     int n, x;
  10.     cin >> n >> x;
  11.     vector<int> niza(n);
  12.     for(int i = 0; i < n; i++){
  13.         cin >> niza[i];
  14.     }
  15.     int s = 0;
  16.     sort(niza.begin(), niza.end());
  17.     for(int i = 0, j = n - 1; ;) {
  18.         if(i > j) break;
  19.         if(niza[i] + niza[j] <= x) {
  20.             i++;
  21.             j--;
  22.         }
  23.         else {
  24.             j--;
  25.         }
  26.         s++;
  27.     }
  28.     cout << s << endl;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement