Submission

Status:

[-SSSSSSSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: kittipos

Problemset: จุดตัดบนกราฟ

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-09 19:51:29

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    int pre = 0;

    priority_queue<int> enter;
    priority_queue<int> drop;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        if (i == 0) {
            pre = temp;
            continue;
        }

        int e = temp;
        int d = pre;
        pre = temp;

        if (e > d) {
            swap(e, d);
        }

        enter.push(e);
        drop.push(d);
    }
    

    int cur = 0;
    int most = 0;
    while (!enter.empty() || !drop.empty()) {
        if (enter.empty()) {
            break;
        }

        if (enter.top() > drop.top()) {
            cur--;
            drop.pop();            
        } else {
            cur++;
            enter.pop();
        }
        most = max(cur, most);
    }

    cout << most;

    return 0;
}