Advertisement
nicuvlad76

Untitled

Feb 12th, 2023
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #define N 500005
  5. using namespace std;
  6. ifstream fin("piscina.in");
  7. ofstream fout("piscina.out");
  8.  
  9. struct coord
  10. {
  11.     int x,y;
  12. }a[N];
  13. int n,m,p;
  14. long long A;
  15. bool comp(coord A,coord B ){return A.y<B.y;}
  16. long long Solutie()
  17. {
  18.     sort(a+1, a+p+1, comp);
  19.     int pred;
  20.     long long ar, armx;
  21.     ar=armx=0;
  22.     pred=1;
  23.     for(int i=1;i<=p;i++)
  24.         if(a[pred].x>a[i].x)
  25.     {
  26.         ar=a[pred].x;
  27.         ar=1LL*ar*a[i].y;
  28.         pred=i;
  29.         armx=max(armx, ar);
  30.     }
  31.     return armx;
  32. }
  33. void F(int n1, int m1)
  34. {
  35.     for(int i=1;i<=n;i++)
  36.         if(a[i].x &&  a[i].y)
  37.     {
  38.         if(n1>0) a[i].x=n1-a[i].x;
  39.         if(m1>0) a[i].y=m1-a[i].y;
  40.     }
  41. }
  42. int main()
  43. {
  44.     fin>>n>>m>>p;
  45.     for(int i=1;i<=p;i++)fin>>a[i].x>>a[i].y;
  46.     p++; a[p].x=n;a[p].y=0;
  47.     p++; a[p].x=0; a[p].y=m;
  48.     A=max(A, Solutie());
  49.     F(n,0);
  50.     A=max(A, Solutie());
  51.     F(0, m);
  52.     A=max(A, Solutie());
  53.     F(n, 0);
  54.     A=max(A, Solutie());
  55.     fout<<A;
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement