Looking at the time and memory, I thought I was going to use some storage structures. The results were circled, and finally I solved it with simple knowledge such as sorting .. Sometimes it is good to be optimistic ..
[Cpp]
# Include <iostream>
# Include <cstring>
# Include <string>
# Include <algorithm>
Using namespace std;
Class war
{
Public:
Int starttime;
Int endtime;
Bool vis;
};
Bool cmp (war a, war B)
{
If (a. endtime! = B. endtime)
Return B. endtime> a. endtime;
Else
Return a. starttime> B. starttime;
}
War tar [150];
Int main ()
{
Int testcase;
While (cin> testcase)
{
Memset (tar, 0, sizeof (tar ));
String tmp;
Int res = 0;
Int flag = 0;
Int stp, edp;
Cin> stp> edp;
For (int I = 0; I <testcase; I ++)
{
Cin> tar [I]. starttime> tar [I]. endtime;
Getline (cin, tmp );
Tar [I]. vis = 0;
}
Sort (tar, tar + testcase, cmp );
If (tar [0]. endtime <edp)
{
Cout <edp <endl;
Continue;
}
For (int I = 0; I <testcase; I ++)
{
If (tar [I]. endtime> = res)
{
If (res> = tar [I]. starttime)
Res = tar [I]. starttime;
}
Else
{
Flag = 1;
Break;
}
}
If (flag = 1)
Cout <res-1 <endl;
Else
Cout <"Badly! "<Endl;
}
Return 0;
}
# Include <iostream>
# Include <cstring>
# Include <string>
# Include <algorithm>
Using namespace std;
Class war
{
Public:
Int starttime;
Int endtime;
Bool vis;
};
Bool cmp (war a, war B)
{
If (a. endtime! = B. endtime)
Return B. endtime> a. endtime;
Else
Return a. starttime> B. starttime;
}
War tar [150];
Int main ()
{
Int testcase;
While (cin> testcase)
{
Memset (tar, 0, sizeof (tar ));
String tmp;
Int res = 0;
Int flag = 0;
Int stp, edp;
Cin> stp> edp;
For (int I = 0; I <testcase; I ++)
{
Cin> tar [I]. starttime> tar [I]. endtime;
Getline (cin, tmp );
Tar [I]. vis = 0;
}
Sort (tar, tar + testcase, cmp );
If (tar [0]. endtime <edp)
{
Cout <edp <endl;
Continue;
}
For (int I = 0; I <testcase; I ++)
{
If (tar [I]. endtime> = res)
{
If (res> = tar [I]. starttime)
Res = tar [I]. starttime;
}
Else
{
Flag = 1;
Break;
}
}
If (flag = 1)
Cout <res-1 <endl;
Else
Cout <"Badly! "<Endl;
}
Return 0;
}