結果

問題 No.2495 Three Sets
ユーザー otoshigootoshigo
提出日時 2024-01-29 20:47:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,884 ms / 3,000 ms
コード長 1,636 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 79,376 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-29 20:47:46
合計ジャッジ時間 30,822 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,056 ms
6,676 KB
testcase_01 AC 1,057 ms
6,676 KB
testcase_02 AC 1,077 ms
6,676 KB
testcase_03 AC 1,094 ms
6,676 KB
testcase_04 AC 1,066 ms
6,676 KB
testcase_05 AC 1,071 ms
6,676 KB
testcase_06 AC 1,099 ms
6,676 KB
testcase_07 AC 1,089 ms
6,676 KB
testcase_08 AC 1,087 ms
6,676 KB
testcase_09 AC 1,075 ms
6,676 KB
testcase_10 AC 1,100 ms
6,676 KB
testcase_11 AC 1,258 ms
6,676 KB
testcase_12 AC 1,268 ms
6,676 KB
testcase_13 AC 1,794 ms
6,676 KB
testcase_14 AC 1,833 ms
6,676 KB
testcase_15 AC 1,872 ms
6,676 KB
testcase_16 AC 1,884 ms
6,676 KB
testcase_17 AC 1,880 ms
6,676 KB
testcase_18 AC 1,109 ms
6,676 KB
testcase_19 AC 1,133 ms
6,676 KB
testcase_20 AC 1,133 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int M=3'000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int na,nb,nc;
    cin>>na>>nb>>nc;
    vector<int>A(na),B(nb),C(nc);
    vector<int>SA(2*M+1),SB(2*M+1),SC(2*M+1);
    for(int i=0;i<na;i++){
        cin>>A[i];
        SA[A[i]+M]++;
    }
    vector<ll>XA(2*M+1);
    XA[2*M]=M*SA[2*M];
    for(int i=2*M-1;i>=0;i--){
        XA[i]=XA[i+1]+(i-M)*SA[i];
        SA[i]+=SA[i+1];
    }
    for(int i=0;i<nb;i++){
        cin>>B[i];
        SB[B[i]+M]++;
    }
    for(int i=0;i<nc;i++){
        cin>>C[i];
        SC[C[i]+M]++;
    }
    ll ans=0,cnt_b=0,sum_b=0;
    for(int j=2*M;j>=-1;j--){
        ll cnt_c=0,sum_c=0;
        for(int k=2*M;k>=-1;k--){
            int ok=2*M,ng=-1;
            while(ok-ng>1){
                int mid=(ok+ng)/2;
                if((mid-M)*cnt_b+sum_c>=0)ok=mid;
                else ng=mid;
            }
            if(ok*cnt_b+sum_c<0){
                chmax(ans,sum_b*cnt_c);
            }else{
                chmax(ans,XA[ok]*cnt_b+sum_b*cnt_c+sum_c*SA[ok]);
            }
            if(k>=0){
                cnt_c+=SC[k];
                sum_c+=(ll)(k-M)*SC[k];
            }
        }
        if(j>=0){
            cnt_b+=SB[j];
            sum_b+=(ll)(j-M)*SB[j];
        }
    }
    cout<<ans<<"\n";
}
0