Josif_tepe

Untitled

Dec 4th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.    
  9.     int n, k;
  10.     cin >> n >> k;
  11.    
  12.     int a[n];
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> a[i];
  15.     }
  16.    
  17.     sort(a, a + n);
  18.     int i = 0;
  19.     int j = n - 1;
  20.    
  21.     int res = 0;
  22.     while(i <= j) {
  23.         if(a[i] + a[j] <= k) {
  24.             i++;
  25.             j--;
  26.         }
  27.         else {
  28.             j--;
  29.         }
  30.         res++;
  31.     }
  32.    
  33.     cout << res << endl;
  34.    
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment