Advertisement
ivangarvanliev

Untitled

Jun 2nd, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n, x;
  7.     cin >> n >> x;
  8.     int tezina[n];
  9.  
  10.     for (int i = 0; i < n; ++i) {
  11.         cin >> tezina[i];
  12.     }
  13.  
  14.     sort(tezina, tezina + n);
  15.  
  16.     int i = 0;
  17.     int j = n - 1;
  18.     int gondoli = 0;
  19.  
  20.     while (i <= j) {
  21.         if (tezina[i] + tezina[j] <= x) {
  22.             ++i;
  23.         }
  24.         --j;
  25.         ++gondoli;
  26.     }
  27.  
  28.     cout << gondoli << endl;
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement