done 3 sorting problems
This commit is contained in:
29
CSES - CSES Problem Set/Ferris_Wheel.cpp
Normal file
29
CSES - CSES Problem Set/Ferris_Wheel.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// Ferris Wheel
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
ll n; cin >> n;
|
||||
ll x; cin >> x;
|
||||
vector<ll> ps(n);
|
||||
for (auto &e: ps) cin >> e;
|
||||
ll count = 0;
|
||||
ll min = 0;
|
||||
ll max = n-1;
|
||||
std::sort(ps.begin(), ps.end());
|
||||
while (min <= max) {
|
||||
if (ps[min] + ps[max] <= x) {
|
||||
max--;
|
||||
min++;
|
||||
count++;
|
||||
} else {
|
||||
max --;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user