1620B - Triangles on a Rectangle - CodeForces Solution


geometry greedy math *1000

Please click on ads to support us..

Python Code:

R=lambda:map(int,input().split())
t,=R()
while t:
 t-=1;w,h=R();r=0
 for x in[h,h,w,w]:k,m,*_,M=R();r=max(r,x*(M-m))
 print(r)
	   	    						 	  	 	  			 		

C++ Code:

#define ll long long
#define ull unsigned long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define pb push_back
#define ff first
#define ss second
#include <bits/stdc++.h>
 
// #include <boost/multiprecision/cpp_ll.hpp>
using namespace std;
/*bool ip(ull n){ //prime check
    bool f = 1;
    if(n==1 || n==0){
        f = 1;
    }
    else{
    for(ull i = 2;i*i<n;i++){
        if(n%i==0){
            f = 0;
            break;
        }
    }
    }
    return f;
}*/
void solve(){
    ll w,h;
    cin >> w >> h;
    ll ans = 0;
    vector<ll> s1,s2,s3,s4;
    int n1,n2,n3,n4;
    cin >> n1;
    for(int i =0;i<n1;i++){
        ll a;
        cin >> a;
        s1.pb(a);
    }
    cin >> n2;
    for(int i =0;i<n2;i++){
        ll a;
        cin >> a;
        s2.pb(a);
    }
    cin >> n3;
    for(int i =0;i<n3;i++){
        ll a;
        cin >> a;
        s3.pb(a);
    }
    cin >> n4;
    for(int i =0;i<n4;i++){
        ll a;
        cin >> a;
        s4.pb(a);
    }
    ll s1d,s2d,s3d,s4d;
    s1d = *max_element(s1.begin(),s1.end()) - *min_element(s1.begin(),s1.end());
    s2d = *max_element(s2.begin(),s2.end()) - *min_element(s2.begin(),s2.end());
    s3d = *max_element(s3.begin(),s3.end()) - *min_element(s3.begin(),s3.end());
    s4d = *max_element(s4.begin(),s4.end()) - *min_element(s4.begin(),s4.end());

    ans = max(max(s1d,s2d)*h,max(s3d,s4d)*w);
    cout << ans << endl;

}

 
int main ()
{
  ios::sync_with_stdio (0);
  cin.tie (0);
  cout.tie (0);
  ll t = 1;
  cin >> t;
  while (t--)
    {
      solve ();
    }
  return 0;
}


Comments

Submit
0 Comments
More Questions

1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums