Advertisement
a53

dreptunghi1

a53
Nov 5th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. /* *********************
  2. Solutie oficiala (100p)
  3. Autor: Vintila Valentin Ioan
  4. ********************* */
  5. #include <bits/stdc++.h>
  6. #define N 20005
  7. using namespace std;
  8. int S[N],D[N];
  9.  
  10. int main()
  11. {
  12. ifstream f("dreptunghi1.in");
  13. int n,m,i,pc=0,j,k,h[N],stiva[N],vf,maxarea=0;
  14. f>>m>>n>>pc;
  15. pair<short,short> v[N];
  16. for(i=0;i<pc;++i)
  17. f>>v[i].first>>v[i].second;
  18. f.close();
  19. sort(v,v+pc);
  20. k=0;
  21. for(i=1;i<=m;++i)
  22. {
  23. for(j=1;j<=n;++j)
  24. {
  25. if(v[k].first==i&&v[k].second==j)
  26. {
  27. h[j]=0;
  28. while(k<pc&&v[k].first==i&&v[k].second==j)
  29. ++k;
  30. h[j]=0;
  31. }
  32. else
  33. ++h[j];
  34. }
  35. vf=0;stiva[vf]=n+1;
  36. for(j=n;j>=1;--j)
  37. {
  38. while(vf>0&&h[j]<=h[stiva[vf]])
  39. --vf;
  40. D[j]=stiva[vf];
  41. stiva[++vf]=j;
  42. }
  43. vf=0;stiva[vf]=0;
  44. for(j=1;j<=n;++j)
  45. {
  46. while(vf>0&&h[j]<=h[stiva[vf]])
  47. --vf;
  48. S[j]=stiva[vf];
  49. stiva[++vf]=j;
  50. }
  51. for(j=1;j<=n;++j)
  52. maxarea=max(maxarea,h[j]*(D[j]-1-S[j]));
  53. }
  54. ofstream g("dreptunghi1.out");
  55. g<<maxarea;
  56. g.close();
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement