1398D - Colored Rectangles - CodeForces Solution


dp greedy sortings *1800

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define pb push_back
using namespace std;
    vector<int> r;
    vector<int> g;
    vector<int> b;
    ll res[201][201][201];
    ll dp(int re,int gr,int bl){
        if(res[re][gr][bl]){
            return res[re][gr][bl];
        }
        ll pom,res1,res2,res3;
        if(re>0&&gr>0)
            res1=dp(re-1,gr-1,bl)+r[re-1]*g[gr-1];
        else
            res1=0;
        if(re>0&&bl>0)
            res2=dp(re-1,gr,bl-1)+r[re-1]*b[bl-1];
        else
            res2=0;
        if(gr>0&&bl>0)
            res3=dp(re,gr-1,bl-1)+g[gr-1]*b[bl-1];
        else
            res3=0;
        res[re][gr][bl]=max(res1,max(res2,res3));
        return res[re][gr][bl];
    }
void solve() {
    int r_,g_,b_;
    cin>>r_>>g_>>b_;
    int pom;
    for(int i=0;i<r_;i++){
        cin>>pom;
        r.pb(pom);
    }
    for(int i=0;i<g_;i++){
        cin>>pom;
        g.pb(pom);
    }
    for(int i=0;i<b_;i++){
        cin>>pom;
        b.pb(pom);
    }
    sort(r.begin(),r.end());
    sort(g.begin(),g.end());
    sort(b.begin(),b.end());
    for(int i=0;i<r_;i++){
        for(int j=0;j<g_;j++){
            for(int k=0;k<b_;k++){
                res[i][j][k]=0;
            }
        }
    }
    for(int i=0;i<r_;i++){
        res[i][0][0]=0;
    }
    for(int i=0;i<g_;i++){
        res[0][i][0]=0;
    }
    for(int i=0;i<b_;i++){
        res[0][0][i]=0;
    }
    pom=dp(r_,g_,b_);
    cout<<pom<<endl;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //FILES
    int t=1;
    /*
    cin>>t;
    //*/
    while(t--) {
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

1097B - Petr and a Combination Lock
92A - Chips
1665B - Array Cloning Technique
1665A - GCD vs LCM
118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel