Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: theem1502
Problemset: จุดตัดบนกราฟ
Language: cpp
Time: 0.038 second
Submitted On: 2026-02-21 00:24:55
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int,int> first, pair<int,int> second) {
if (first.first > second.first) {
return false;
}
if (first.first < second.first) {
return true;
}
if (first.second > second.first) {
return true;
}
return false;
}
int main() {
int num;
cin >> num;
vector<int> thearray(num);
for (int i =0; i < num; i++) {
cin >> thearray[i];
}
vector<pair<int,int>> sweep;
for (int i = 1; i < num; i++) {
int first = max(thearray[i-1], thearray[i]), second = min(thearray[i-1], thearray[i]);
sweep.push_back(make_pair(second, 1));
sweep.push_back(make_pair(first, -1));
}
sort(sweep.begin(), sweep.end());
/*
for (auto [x,y]:sweep) {
cout << x << " ";
}
cout << "\n";
*/
int counter = 0;
int maxcount = 0;
for (int i = 0; i < sweep.size(); i++) {
counter += sweep[i].second;
if (counter > maxcount){
maxcount = counter;
}
}
cout << maxcount;
}