結果

問題 No.2495 Three Sets
ユーザー a_s_ka_s_k
提出日時 2023-11-15 14:24:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 428 ms / 3,000 ms
コード長 1,952 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 209,380 KB
実行使用メモリ 8,844 KB
最終ジャッジ日時 2023-11-15 14:24:46
合計ジャッジ時間 4,908 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 75 ms
6,676 KB
testcase_14 AC 176 ms
7,596 KB
testcase_15 AC 68 ms
6,676 KB
testcase_16 AC 428 ms
8,844 KB
testcase_17 AC 404 ms
8,844 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 97 ms
8,844 KB
testcase_20 AC 88 ms
8,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, m, n) for (ll i = m; i < n; i++)
#define Endl endl
vector<ll> sa, sb, sc;
ll A, B, C;
ll f(ll s, ll t, ll u)
{
    return sa[s] * t + sb[t] * u + sc[u] * s;
}
ll g(ll i, ll j)
{
    ll sub = -1e18;
    if (f(i, j, C - 1) <= f(i, j, C))
        sub = max(sub, f(i, j, C));
    else if (f(i, j, 0) > f(i, j, 1))
        sub = max(sub, f(i, j, 0));
    else
    {
        ll l = 0;
        ll r = C - 1;
        while (r - l > 1)
        {
            ll search = l + (r - l) / 2;
            if (f(i, j, search) <= f(i, j, search + 1))
                l = search;
            else
                r = search;
        }
        sub = max(sub, f(i, j, r));
    }
    return sub;
}
int main()
{
    cin >> A >> B >> C;
    vector<ll> a(A), b(B), c(C);
    rep(i, 0, A) cin >> a[i];
    rep(i, 0, B) cin >> b[i];
    rep(i, 0, C) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());
    sa.push_back(0);
    sb.push_back(0);
    sc.push_back(0);
    rep(i, 0, A)
    {
        sa.push_back(sa[i] + a[i]);
    }
    rep(i, 0, B)
    {
        sb.push_back(sb[i] + b[i]);
    }
    rep(i, 0, C)
    {
        sc.push_back(sc[i] + c[i]);
    }
    ll ans = -1e18;
    rep(i, 0, A + 1)
    {
        
        if(g(i,0)>g(i,1))ans=max(ans,g(i,0));
        else if(g(i,B-1)<g(i,B))ans=max(ans,g(i,B));
        else {
            ll l=0;
            ll r=B-1;
            while(r-l>1){
                ll search=l+(r-l)/2;
                if(g(i,search)<=g(i,search+1))l=search;
                else r=search;
            }
            ans=max(ans,g(i,r));
        }
        /*rep(j, 0, B + 1)
        {
            ans=max(ans,g(i,j));
            cout<<g(i,j)<<endl;
        }
        cout<<endl;*/
    }
    cout << ans << endl;
}
0