| 21 | |
| 22 | |
| 23 | int main(){ |
| 24 | int n, x; |
| 25 | cin>>n>>x; |
| 26 | int a[n]; |
| 27 | for(int i=0;i<n;i++){ |
| 28 | cin>>a[i]; |
| 29 | } |
| 30 | #Sorting the array |
| 31 | sort(a, a+n); |
| 32 | long long tot = 0; |
| 33 | long long count = 0; // initialize the count variable to keep track of the reequired gondolas. |
| 34 | if (n==1) cout<<"1"; |
| 35 | else{ |
| 36 | int i=0,j=n-1; |
| 37 | while(i<=j){ |
| 38 | tot=a[i]+a[j]; // In each iteration it is important to calculate the sum of i-th front and j-th back element. |
| 39 | if(tot<=x){ |
| 40 | count++; |
| 41 | i++; |
| 42 | j--; |
| 43 | tot = 0; |
| 44 | } |
| 45 | else{ |
| 46 | j--; |
| 47 | count++; |
| 48 | tot = 0; |
| 49 | } |
| 50 | } |
| 51 | cout<<count; |
| 52 | } |
| 53 | } |
nothing calls this directly
no outgoing calls
no test coverage detected