-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBYTESE2.cpp
More file actions
66 lines (62 loc) · 1.08 KB
/
BYTESE2.cpp
File metadata and controls
66 lines (62 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<iostream>
using namespace std;
struct node
{
int z;
int info;
node *next;
};
void insert(node **q,int a,int b)
{
node *temp=new node;
temp->info=a;
temp->next=NULL;
temp->z=b;
if(*q==NULL)
*q=temp;
else
{
node *t=*q;
node *p=NULL;
while(t!=NULL && t->info<temp->info)
{
p=t;
t=t->next;
}
if(t==NULL)
p->next=temp;
else
{
if(p==NULL)
*q=temp;
else
p->next=temp;
temp->next=t;
}
}
}
int main()
{
long int t,n,x,y;
cin>>t;
while(t--)
{
long int max=0,sum=0;
node *q=NULL;
cin>>n;
while(n--)
{
cin>>x>>y;
insert(&q,x,1);
insert(&q,y,-1);
}
while(q!=NULL)
{
sum=sum+q->z;
if(sum>max)
max=sum;
q=q->next;
}
cout<<max<<"\n";
}
}