josiftepe

Untitled

Oct 17th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <fstream>
  14. using namespace std;
  15.  
  16. int main() {
  17. int n,x,res=0;
  18. bool nmz=false;
  19. cin>>n>>x;
  20. vector <int> v(n);
  21. for (int i=0;i<n;i++){
  22.     cin>>v[i];
  23. }
  24. sort( v.begin(),v.end());
  25.     for (int i=0,j=n-1;i<=j;){
  26.     if (v[i]+v[j]<=x){
  27.         res++;
  28.         i++;
  29.         j--;
  30.     }
  31.     else if(v[i]+v[j]>x) {
  32.         j--;
  33.         res++;
  34.     }
  35.    
  36.        
  37. }
  38.     cout <<res;
  39.  
  40.  
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment