Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- struct tacka
- {
- int x,y;
- };
- bool prov(tacka a,tacka b)
- {
- return a.x<b.x;
- }
- int main()
- {
- long n;
- cin>>n;
- if(n==1||n==2)
- {
- cout<<n;
- return -1;
- }
- tacka niz[n];
- for (int i=0;i<n;i++)
- {
- cin>>niz[i].x>>niz[i].y;
- }
- sort(niz,niz+n,prov);
- long pov=0,pr=0;
- int br =0;
- int ind=-1;
- while(br!=n-1)
- {
- pr=abs(niz[br].x-niz[br+1].x)*abs(niz[br].y-niz[br+1].y);
- if(pr>pov)
- {
- pov=pr;
- ind=br;
- }
- if(pr==pov&&( (abs(niz[0].x-niz[br].x)*abs(niz[0].y-niz[br].y)+abs(niz[n-1].x-niz[br+1].x)*abs(niz[n-1].y-niz[br+1].y)) < (abs(niz[0].x-niz[ind].x)
- *abs(niz[0].y-niz[ind].y)+
- abs(niz[n-1].x-niz[ind+1].x)*
- abs(niz[n-1].y-niz[ind+1].y))))
- {
- pov=pr;
- ind=br;
- }
- br++;
- pr=0;
- }
- int mak=0,mas=0,minn=19000,mins=19000;
- for(int i=0;i<=ind;i++)
- {
- mak=max(niz[i].y,mak);
- minn=min(niz[i].y,minn);
- }
- for(int i=ind+1;i<n;i++)
- {
- mas=max(niz[i].y,mas);
- mins=min(niz[i].y,mins);
- }
- long povr=abs(niz[0].x-niz[ind].x)*abs(minn-mak)+abs(niz[n-1].x-niz[ind+1].x)*abs(mins-mas);
- if(niz[0].x==niz[ind].x)
- povr++;
- if(niz[n-1].x==niz[ind+1].x)
- povr++;
- cout<<povr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement