Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Krovmoroz

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

Language: cpp

Time: 0.023 second

Submitted On: 2026-01-16 22:27:21

#include <bits/stdc++.h>
using namespace std;

int N,pre,cur,curs = 0,ans = 0;
vector<pair<int,int>> evnt;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N >> pre;
    for(int i = 1; i < N;i ++) {
      cin >> cur;

      int l = min(pre,cur);
      int r = max(pre,cur);
      evnt.push_back({l,1});
      evnt.push_back({r,-1});

      pre = cur;
    }

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

    for (auto &x : evnt) {
      curs += x.second;
      ans = max(ans,curs);
    }

    cout << ans;
    return 0;
}