File tree 1 file changed +57
-0
lines changed
C Programs/C Programs - 3 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < cstdio>
2
+ #include < vector>
3
+ #include < algorithm>
4
+ using namespace std ;
5
+
6
+ #define all (v ) (v).begin(), (v).end()
7
+
8
+ struct log {
9
+ int time, type;
10
+ };
11
+
12
+ int compare (const log &A, const log &B)
13
+ {
14
+ return (A.time <= B.time );
15
+ }
16
+
17
+ void solve ()
18
+ {
19
+ const int ENTRY = 0 , EXIT = 1 ;
20
+
21
+ int no_of_people;
22
+ scanf (" %d" , &no_of_people);
23
+
24
+ vector <log > event (2 *no_of_people);
25
+
26
+ for (int i = 0 ; i < no_of_people; i++)
27
+ {
28
+ scanf (" %d %d" , &event[2 *i].time , &event[2 *i + 1 ].time );
29
+
30
+ event[2 *i].type = ENTRY;
31
+ event[2 *i + 1 ].type = EXIT;
32
+ }
33
+
34
+ sort (all (event), compare);
35
+
36
+ int no_of_inside_people = 0 ;
37
+ int max_people = 0 ;
38
+
39
+ for (int i = 0 ; i < event.size (); i++)
40
+ {
41
+ no_of_inside_people += (event[i].type == ENTRY ? 1 : -1 );
42
+ max_people = max (no_of_inside_people, max_people);
43
+ }
44
+
45
+ printf (" %d\n " , max_people);
46
+ }
47
+
48
+ int main ()
49
+ {
50
+ int no_of_test_cases;
51
+ scanf (" %d" , &no_of_test_cases);
52
+
53
+ while (no_of_test_cases--)
54
+ solve ();
55
+
56
+ return 0 ;
57
+ }
You can’t perform that action at this time.
0 commit comments