Ferris Wheel

PHOTO EMBED

Sun Sep 19 2021 11:26:40 GMT+0000 (Coordinated Universal Time)

Saved by @Naredra

#include<bits/stdc++.h>
using namespace std ; 
#define ll long long 

int main()
{   
    const  int mxN = 2e5;
    int n ,  m , a[mxN];
    cin>>n>>m;
    for(int i =0;i<n;i++)
    {
        cin>>a[i];
    }
    
    sort(a,a+n);
    int ans = 1;
    int i =0 ; 
    int j = n-1;
    while(i<j)
    {
        if(a[i]+a[j]<m)
        {
            ans = ans+1;
            i++;
        }
        else
        {
            i++;
            j--;
            ans = ans+1;
        }
    }
   
    cout<<ans;
    
    
    
    
}
content_copyCOPY

There are n children who want to go to a Ferris wheel, and your task is to find a gondola for each child. Each gondola may have one or two children in it, and in addition, the total weight in a gondola may not exceed x. You know the weight of every child. What is the minimum number of gondolas needed for the children? Input The first input line contains two integers n and x: the number of children and the maximum allowed weight. The next line contains n integers p1,p2,…,pn: the weight of each child. Output Print one integer: the minimum number of gondolas. Constraints 1≤n≤2⋅105 1≤x≤109 1≤pi≤x Example Input: 4 10 7 2 3 9 Output: 3