D. Colored Rectangles -DP 排序

Problem - 1398D - Codeforces

D. Colored Rectangles

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given three multisets of pairs of colored sticks:

  • RR pairs of red sticks, the first pair has length r1r1, the second pair has length r2r2, ……, the RR-th pair has length rRrR;
  • GG pairs of green sticks, the first pair has length g1g1, the second pair has length g2g2, ……, the GG-th pair has length gGgG;
  • BB pairs of blue sticks, the first pair has length b1b1, the second pair has length b2b2, ……, the BB-th pair has length bBbB;

You are constructing rectangles from these pairs of sticks with the following process:

  1. take a pair of sticks of one color;
  2. take a pair of sticks of another color different from the first one;
  3. add the area of the resulting rectangle to the total area.

Thus, you get such rectangles that their opposite sides are the same color and their adjacent sides are not the same color.

Each pair of sticks can be used at most once, some pairs can be left unused. You are not allowed to split a pair into independent sticks.

What is the maximum area you can achieve?

Input

The first line contains three integers RR, GG, BB (1≤R,G,B≤2001≤R,G,B≤200) — the number of pairs of red sticks, the number of pairs of green sticks and the number of pairs of blue sticks.

The second line contains RR integers r1,r2,…,rRr1,r2,…,rR (1≤ri≤20001≤ri≤2000) — the lengths of sticks in each pair of red sticks.

The third line contains GG integers g1,g2,…,gGg1,g2,…,gG (1≤gi≤20001≤gi≤2000) — the lengths of sticks in each pair of green sticks.

The fourth line contains BB integers b1,b2,…,bBb1,b2,…,bB (1≤bi≤20001≤bi≤2000) — the lengths of sticks in each pair of blue sticks.

Output

Print the maximum possible total area of the constructed rectangles.

Examples

input

Copy

1 1 1
3
5
4

output

Copy

20

input

Copy

2 1 3
9 5
1
2 8 5

output

Copy

99

input

Copy

10 1 1
11 7 20 15 19 14 2 4 13 14
8
11

output

Copy

372

Note

In the first example you can construct one of these rectangles: red and green with sides 33 and 55, red and blue with sides 33 and 44 and green and blue with sides 55 and 44. The best area of them is 4×5=204×5=20.

In the second example the best rectangles are: red/blue 9×89×8, red/blue 5×55×5, green/blue 2×12×1. So the total area is 72+25+2=9972+25+2=99.

In the third example the best rectangles are: red/green 19×819×8 and red/blue 20×1120×11. The total area is 152+220=372152+220=372. Note that you can't construct more rectangles because you are not allowed to have both pairs taken to be the same color.

========================================================================

显然是优先大的配大的,故从大到小排序一下,然后进行DP,本次可以由 i-1, j-1, k-1 三者分别进行承接,也可以用 i-1&&j-1 ,  i-1&&k-1  ,j-1&&k-1进行更新,至于 i-1&&j-1&k-1 是劣与前两者的,不必考虑

特别注意的是,DP枚举的范围应该有0,否则过不去样例2

# include<bits/stdc++.h>

using namespace std;
# define mod 1000000007
typedef long long int ll;

ll a[210],b[210],c[210];
ll dp[210][210][210];


bool cmp(ll x,ll y)
{
    return x>y;

}
int main ()
{

  int n1,n2,n3;
  cin>>n1>>n2>>n3;

  for(int i=1;i<=n1;i++)
  {
      cin>>a[i];
  }

  for(int i=1;i<=n2;i++)
  {
      cin>>b[i];
  }

  for(int i=1;i<=n3;i++)
  {
      cin>>c[i];
  }

  sort(a+1,a+1+n1,cmp);
  sort(b+1,b+1+n2,cmp);
  sort(c+1,c+1+n3,cmp);


  ll ans=0;
  for(int i=0;i<=n1;i++)
  {
      for(int j=0;j<=n2;j++)
      {
          for(int k=0;k<=n3;k++)
          {
              if(i)
              dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k]);
              if(j)
              dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
              if(k)
              dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]);
              if(i&&j)
              dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k]+a[i]*b[j]);
              if(j&&k)
              dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+b[j]*c[k]);
              if(i&&k)
              dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+a[i]*c[k]);

              ans=max(ans,dp[i][j][k]);
          }
      }
  }

 cout<<ans;

    return 0;

}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值