forked from Abhijeet5665/c-programs-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakashpandey.txt
126 lines (114 loc) · 2.54 KB
/
akashpandey.txt
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
struct pairs {
long int first;
long int second;
};
int partition(struct pairs a[],int l,int u);
void quick_sort(struct pairs a[],int l,int u)
{
int j;
if(l<u)
{
j=partition(a,l,u);
quick_sort(a,l,j-1);
quick_sort(a,j+1,u);
}
}
int partition(struct pairs a[],int l,int u)
{
int i,j;
struct pairs v,temp;
v=a[l];
i=l;
j=u+1;
if(a[i].first==v.first){
do
{
do
i++;
while(a[i].second<v.second&&i<u);
do
j--;
while(v.second<a[j].second);
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}while(i<j);
a[l]=a[j];
a[j]=v;
}
else{
do
{
do
i++;
while(a[i].first<v.first&&i<u);
do
j--;
while(v.first<a[j].first);
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}while(i<j);
a[l]=a[j];
a[j]=v;}
return(j);
}
int main(){
long c;
int n,k,f=1;
cin>>c>>n>>k;
struct pairs a[n];
for(int i=0;i<n;i++)
cin>>a[i].first>>a[i].second;
quick_sort(a,0,n-1);
if(k==1){
pairs max;
if(c-a[n-1].second>a[0].first-1){
max.first=a[n-1].second+1;
max.second=c;
}
else{
max.first=1;
max.second=a[0].first-1;
}
for(int i=0;i<n-1;i++){
if(a[i+1].first-a[i].second-1>max.second-max.first+1)
{max.first=a[i].second+1;max.second=a[i+1].first-1;
}
}
for(int i=0;i<n-1;i++){
if(a[i].second>=a[i+1].first){
if(a[i+1].second-a[i+1].first>max.second-max.first){
if(a[i].second-a[i].first>max.second-max.first)
{f=0;break;}
a[i].first=max.first;
a[i].second=max.second;break;}
else{
a[i+1].first=max.first;
a[i+1].second=max.second;break;}
}}//cout<<max.first<<" "<<max.second;
quick_sort(a,0,n-1);
}
for(int i=0;i<n-1;i++){
if(a[i].second>=a[i+1].first){
f=0;
break;
}
}
if(f)
cout<<"Good"<<endl;
else
cout<<"Bad"<<endl;
//cout<<max.first<<" "<<max.second;
// your code goes here
return 0;
}