[백준] 22988 재활용 캠페인💫

0

백준

목록 보기
267/271
post-thumbnail

틀린 풀이

  • 맞왜틀
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>

using namespace std;

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n; 
    cin >> n;
    ll x; 
    cin >> x;

    vector<ll> C;
    int answer = 0;
    for (int i = 0; i < n; i++) {
        ll k; 
        cin >> k;
        if (k >= x) answer++;
        else C.push_back(k);
    }
    sort(C.begin(), C.end());

    int remain = 0;
    int l = 0; int r = C.size() - 1;
    while (l < r) {
        ll d1 = C[l];
        ll d2 = C[r];

        if ((d1 + d2) >= (x / 2)) {
            answer++;
            l++; r--;
        }
        else {
            remain++;
            l++;
        }
    }
    if (l == r) remain++;

    //투포인터 후 남은 병들의 수 /3
    answer += (remain / 3);
    cout << answer;
}

profile
Be able to be vulnerable, in search of truth

0개의 댓글