cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

ferris_wheel_1090.cpp (340B)


      1 #include <algorithm>
      2 #include <iostream>
      3 #include <vector>
      4 
      5 int main() {
      6 	int n, x;
      7 	std::cin >> n >> x;
      8 	std::vector<int> a(n);
      9 	for (int i = 0; i < n; i++)
     10 		std::cin >> a[i];
     11 	std::sort(a.begin(), a.end());
     12 	size_t i{0}, j{a.size()-1}, s{0};
     13 	for (; j > i; j--, s++)
     14 		i += a[i] + a[j] <= x;
     15 	if (i == j) s++;
     16 	std::cout << s << "\n";
     17 }