結果

問題 No.2495 Three Sets
ユーザー milanis48663220milanis48663220
提出日時 2023-10-07 01:51:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,048 ms / 3,000 ms
コード長 3,550 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 130,056 KB
実行使用メモリ 5,036 KB
最終ジャッジ日時 2023-10-07 01:51:08
合計ジャッジ時間 7,606 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 889 ms
4,384 KB
testcase_14 AC 927 ms
4,580 KB
testcase_15 AC 765 ms
4,388 KB
testcase_16 AC 1,043 ms
5,036 KB
testcase_17 AC 1,048 ms
5,032 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 32 ms
4,692 KB
testcase_20 AC 30 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using P = pair<ll, ll>;

vector<P> run_length(vector<int> v){
    int x = v[0];
    int cnt = 1;
    vector<P> ans;
    for(int i = 1; i < v.size(); i++){
        if(x == v[i]){
            cnt++;
        }else{
            ans.push_back({x, cnt});
            x = v[i];
            cnt = 1;
        }
    }
    ans.push_back({x, cnt});
    return ans;
}

ll floor_div(ll x, ll y){
    if(x%y == 0) return x/y;
    if(x > 0) return x/y;
    return x/y-1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    vector<int> n(3);
    for(int i = 0; i < 3; i++) cin >> n[i];
    vector<vector<int>> v(3);
    vector<vector<P>> vp(3);
    for(int i = 0; i < 3; i++){
        v[i].resize(n[i]);
        for(int j = 0; j < n[i]; j++){
            cin >> v[i][j];
        }
        sort(v[i].begin(), v[i].end(), greater<int>());
        auto u = run_length(v[i]);
        ll sum = 0;
        ll cnt = 0;
        vp[i].push_back({sum, cnt});
        for(auto [x, c]: u){
            sum += x*c;
            cnt += c;
            vp[i].push_back({sum, cnt});
        }
    }
    ll ans = 0;
    for(int j = 0; j < vp[1].size(); j++){
        auto [sum1, cnt1] = vp[1][j];
        for(int k = 0; k < vp[2].size(); k++){
            auto [sum2, cnt2] = vp[2][k];
            chmax(ans, sum1*cnt2);
            // for(int i = 0; i < v[0].size(); i++){
            //     auto [sum0, cnt0] = vp[0][i];
            //     chmax(ans, sum0*cnt1+sum1*cnt2+sum2*cnt0);
            // }
        }
    }
    // debug_value(ans)
    ll sum = accumulate(v[2].begin(), v[2].end(), 0ll);
    for(int j = 0; j < vp[1].size(); j++){
        auto [sum1, cnt1] = vp[1][j];
        int k = v[2].size()-1;
        ll sum2 = sum;
        vector<int> indices(vp[0].size()-1);
        for(int i = 1; i < vp[0].size(); i++) indices[i-1] = i;
        if(sum1 < 0) reverse(indices.begin(), indices.end());
        for(int i: indices){
            auto [sum0, cnt0] = vp[0][i];
            ll lim = floor_div(-sum1, cnt0);
            while(k >= 0 && v[2][k] <= lim) {
                sum2 -= v[2][k];
                k--;
            }
            ll cnt2 = k+1;
            chmax(ans, sum0*cnt1+sum1*cnt2+sum2*cnt0);
            // cout << sum1 << ' ' << cnt0 << ":" << lim << ' ';
        }
        // cout << endl;
    }
    
    cout << ans << endl;
}
0