Question Link
- Question:
N groups of people, each group has a row of input: number of people, arrival time, departure time. Ask the maximum number of people (if someone leaves at the same time, let people leave first)
- Analysis:
Split a group of people into two points, left and right, scanning from left to right. If you encounter a left endpoint, add it to the Set; if you encounter a right endpoint, delete the corresponding vertex in the set.
Const int maxn = 110000; struct node {int num, ISR, ID, time; bool operator <(const node & RHs) const {If (time! = RHS. time) return time <RHS. time; return ISR> RHS. ISR ;}} IPT [maxn]; int main () {int t, a, B, c, d, n, num; RI (t); Fe (Kase, 1, t) {RI (n); rep (I, n) {scanf ("% d: % d", & num, &, & B, & C, & D); int x = I <1, y = x | 1; ARIMA [X]. ISR = 0; ARIMA [X]. time = A * 60 + B; EPT [Y]. ISR = 1; IPT [Y]. time = C * 60 + D; EPT [X]. id = IPT [Y]. id = I; IPT [X]. num = IPT [Y]. num = num;} n <= 1; sort (EPT, IPT + n); set <int> st; int ans = 0, Tans = 0; rep (I, n) {If (EPT [I]. ISR) {St. erase (IPT [I]. ID); Tans-= IPT [I]. num;} else {St. insert (IPT [I]. ID); tans + = IPT [I]. num;} ans = max (ANS, Tans);} wi (ANS);} return 0 ;}