Advertisement
Junaid_Hossain

Ferris Wheel

Oct 23rd, 2023
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int n, x;
  6.     cin >> n >> x;
  7.     vector<int> weight;
  8.  
  9.     for(int i=0; i<n; i++){
  10.         int input;
  11.         cin >> input;
  12.         weight.push_back(input);
  13.     }
  14.  
  15.     sort(weight.begin(), weight.end());
  16.     int count=0;
  17.  
  18.     while(weight.empty()==0){
  19.         int first = weight[0];
  20.         weight.erase(weight.begin());
  21.         if(first+weight[0]<=x){
  22.             count++;
  23.             weight.erase(weight.begin());
  24.         }else{
  25.             count++;
  26.         }
  27.     }
  28.  
  29.     cout << count << endl;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement