Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int n, x;
- cin >> n >> x;
- vector<int> niza(n);
- for(int i = 0; i < n; i++){
- cin >> niza[i];
- }
- sort(niza.begin(), niza.end());
- // 9
- // 10
- // 10 - 9
- int s = n;
- for(int i = 0; i < (int) niza.size(); i++) {
- int L = i + 1, R = (int) niza.size() - 1;
- int l = -1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(niza[i] + niza[middle] > x) {
- R = middle - 1;
- }
- else {
- l = max(l, middle);
- L = middle + 1;
- }
- }
- if(l != -1) {
- s--;
- niza.erase(niza.begin() + l);
- }
- }
- cout << s << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement