Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: goine

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

Language: cpp

Time: 0.047 second

Submitted On: 2026-03-11 11:46:41

#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<long long> points(n);
    for (auto& p: points) cin >> p;

    vector<pair<long long, int>> events;
    for (int i = 0; i < n - 1; i++) {
        long long high = max(points[i], points[i+1]);
        long long low = min(points[i], points[i+1]);

        events.push_back({high, -1});
        events.push_back({low, 1});
    }

    sort(events.begin(), events.end());

    int cur = 0; 
    int ans = 0;

    for (auto& [y, type]: events) {
        cur += type;
        ans = max(cur, ans);
    }

    cout << ans << '\n';

    return 0;
}