This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
struct ura
{
int a,b;
};
vector<ura>vec;
int inter(int i,int j)
{
return max(0,min(vec[i].b,vec[j].b)-max(vec[i].a,vec[j].a));
}
int reun(int i,int j)
{
return max(vec[i].b,vec[j].b)-min(vec[i].a,vec[j].a);
}
int main()
{
int n,i,j,k,l,r,z;
cin>>n;
char tip;
for(i=1;i<=n;i++)
{
cin>>tip;
if(tip=='A')
{
cin>>l>>r;
vec.push_back({l,r});
}
else if(tip=='R')
{
cin>>l>>r;
for(j=0;j<vec.size();j++)
{
if(vec[j].a==l && vec[j].b==r)
{
vec.erase(vec.begin()+j);
break;
}
}
}
int minim=1e9,sol;
for(j=0;j<vec.size();j++)
{
for(z=j;z<vec.size();z++)
{
if(inter(z,j)<minim)
{
minim=inter(z,j);
sol=reun(z,j);
}
else if(inter(z,j)==minim)
{
sol=min(sol,reun(z,j));
}
}
}
cout<<sol<<'\n';
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(j=0;j<vec.size();j++)
| ~^~~~~~~~~~~
Main.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(j=0;j<vec.size();j++)
| ~^~~~~~~~~~~
Main.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(z=j;z<vec.size();z++)
| ~^~~~~~~~~~~
Main.cpp:21:15: warning: unused variable 'k' [-Wunused-variable]
21 | int n,i,j,k,l,r,z;
| ^
Main.cpp:60:20: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | cout<<sol<<'\n';
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |