cses

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

ferris_wheel.cpp (640B)


      1 #include <bits/stdc++.h>
      2 
      3 using namespace std;
      4 
      5 using ui = unsigned int;
      6 using l = long;
      7 using ul = unsigned long;
      8 using ll = long long;
      9 using ull = unsigned long long;
     10 
     11 using vi = vector<int>;
     12 using vui = vector<ui>;
     13 using vl = vector<l>;
     14 using vul = vector<ul>;
     15 using vll = vector<ll>;
     16 using vull = vector<ull>;
     17 
     18 void solve()
     19 {
     20 	int n, x;
     21 	cin >> n >> x;
     22 	int p[n];
     23 	for (int i = 0; i < n; i++)
     24 		cin >> p[i];
     25 	int i = 0, j = n-1;
     26 
     27 	sort(p, p+n);
     28 
     29 	int res = 0;
     30 	while (i <= j) {
     31 		if (i == j) {
     32 			j--;
     33 		} else if (p[i] + p[j] > x) {
     34 			j--;
     35 		} else {
     36 			i++;
     37 			j--;
     38 		}
     39 		res++;
     40 	}
     41 
     42 	cout << res << "\n";
     43 }
     44 
     45 int main()
     46 {
     47 	solve();
     48 }