CSES Solutions
#1090Sorting and Searching

Ferris Wheel

View on CSES

Solution

1090-Ferris_Wheel.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  int n,x; cin>>n>>x;
7  int a[n]; for(auto&e:a) cin>>e;
8  sort(a,a+n);
9  int ans=0;
10  for(int i=0,j=n-1;i<=j;++i,--j){
11    while(i<=j&&a[i]+a[j]>x) --j,++ans;
12    if(i<=j) ++ans;
13  }
14  cout<<ans<<'\n';
15  return 0;
16}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.