cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

commit 58a87134b164074107e7a97261810f594e7b289a
parent cc8772b051522fc19f8c9f5370602b68b0b42b58
Author: superpozycja <anna@superpozycja.net>
Date:   Sun, 27 Oct 2024 14:28:24 +0100

solve ferris wheel

Diffstat:
Asorting_and_searching/ferris_wheel.cpp | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/sorting_and_searching/ferris_wheel.cpp b/sorting_and_searching/ferris_wheel.cpp @@ -0,0 +1,48 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + int n, x; + cin >> n >> x; + int p[n]; + for (int i = 0; i < n; i++) + cin >> p[i]; + int i = 0, j = n-1; + + sort(p, p+n); + + int res = 0; + while (i <= j) { + if (i == j) { + j--; + } else if (p[i] + p[j] > x) { + j--; + } else { + i++; + j--; + } + res++; + } + + cout << res << "\n"; +} + +int main() +{ + solve(); +}