fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<cmath>
  5. #define pb push_back
  6. #define N 100000
  7. #define ll long long
  8. using namespace std;
  9.  
  10. vector<pair<ll,ll> > v;
  11. bool par=false;
  12.  
  13. bool checkpar(ll a,ll b){
  14. return (a&1 && b&1);
  15. }
  16.  
  17. ll solve(int n){
  18. ll ar=0,s1,s2,s3,m=0,m2,imax,vmax;
  19. s1=0;
  20. s2=v[n-1].second;imax=n-1;
  21. for(int i=n-2;i>=0;i--){
  22. s3=v[i].second;
  23. if(s3<=s2){
  24. if(s3<=s1)continue;
  25. s1=s3;
  26. ar=v[i].first*s1;
  27. m=ar>m?ar:m;
  28. }
  29. else{
  30. s2=s3;
  31. vmax=v[imax].second;
  32. if(s2>>1 >= vmax)
  33. {
  34. ar=(s2*v[i].first)>>1;
  35. m=ar>=m?ar:m;
  36. par=checkpar(s2,v[i].first);
  37. }
  38. else{
  39. ar=vmax*v[i].first;
  40. if(ar>m){m=ar;par=false;}
  41. }
  42.  
  43. imax=i;
  44. }
  45.  
  46. }
  47.  
  48. return m;
  49. }
  50.  
  51. int main()
  52. {
  53. int n,k=0;
  54. ll l,w,max=0,m2;
  55.  
  56. cin >> n;
  57. for(int i=0;i<n;i++){
  58. cin>>l>>w;
  59. if(l<=w) v.pb(make_pair(l,w));
  60. else v.pb(make_pair(w,l));
  61. }
  62. sort(v.begin(),v.end());
  63. max=solve(n);
  64. m2=(v[n-1].first*v[n-1].second)>>1;
  65. if(m2>=max){par=checkpar(v[n-1].first,v[n-1].second);max=m2;}
  66.  
  67. if(par)
  68. cout<<max<<".5";
  69. else
  70. cout<<max<<".0";
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 4356KB
stdin
Standard input is empty
stdout
2.0