fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define timer ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  6.  
  7. #define fi first
  8. #define se second
  9. #define pii pair<int,int>
  10. #define pll pair<ll,ll>
  11. #define unmap unordered_map
  12. #define pb push_back
  13. #define ub upper_bound
  14. #define lb lower_bound
  15. #define bins binary_search
  16.  
  17. const int maxn = 3e5+5;
  18.  
  19. ll w,h;
  20. int n;
  21. pair<ll,ll>d[maxn];
  22. signed main(){
  23. timer;
  24. cin>>w>>h>>n;
  25. ll xmin=1e9+1,xmax=-1e9-1;
  26. for(int i=1;i<=n;i++){
  27. cin>>d[i].fi>>d[i].se;
  28. }
  29. ll res=1e9+1;
  30. for(ll i=1;i<=w;i++){
  31. for(ll j=i;j<=w;j++){
  32. for(int k=1;k<=n;k++){
  33. if(d[k].se<i||d[k].se>j){
  34. xmin=min(xmin,d[k].fi);
  35. xmax=max(xmax,d[k].fi);
  36. }
  37. }
  38. res=min(res,max(j-i+1,xmax-xmin+1));
  39. xmin=1e9+1,xmax=-1e9-1;
  40. }
  41. }
  42. cout<<res;
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5444KB
stdin
5 6 5
5 4
2 6
4 1
2 3
1 4
stdout
3