結果

問題 No.2284 Assembly
ユーザー HIcoderHIcoder
提出日時 2023-07-08 11:16:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,367 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 108,916 KB
実行使用メモリ 9,668 KB
最終ジャッジ日時 2023-09-29 12:40:45
合計ジャッジ時間 4,150 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 83 ms
9,428 KB
testcase_09 AC 84 ms
9,668 KB
testcase_10 AC 86 ms
9,652 KB
testcase_11 AC 83 ms
9,364 KB
testcase_12 AC 85 ms
9,488 KB
testcase_13 AC 82 ms
9,496 KB
testcase_14 AC 82 ms
9,616 KB
testcase_15 AC 83 ms
9,320 KB
testcase_16 AC 85 ms
9,360 KB
testcase_17 AC 84 ms
9,412 KB
testcase_18 AC 92 ms
9,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,int> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;


int main(){
    int N;
    cin>>N;
    vector<ll> A(N),B(N);
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
    }

    /*
    vector<int> order(N);
    iota(order.begin(),order.end(),0);

    sort(order.begin(),order.end(),
    [&](const int lhs,const int rhs){
        if(B[lhs]!=B[rhs]){
            return B[lhs]>B[rhs];
        }else{
            return A[lhs]<A[rhs];
        }
    });

    vector<ll> sumB(N,0);
    sumB[0]=B[order[0]];
    for(int i=1;i<N;i++){
        sumB[i]=sumB[i-1]+B[order[i]];
    }

    ll ans=0;
    
    for(int i=1;i<N;i++){
        ans+=sumB[i-1]*A[order[i]];
    }

    cout<<ans<<endl;
    */
    vector<ll> sumA(N+1),sumB(N+1);
    sumA[N-1]=A[N-1];
    sumB[N-1]=B[N-1];

    for(int i=N-2;i>=0;i--){
        sumA[i]=sumA[i+1]+A[i];
        sumB[i]=sumB[i+1]+B[i];
    }

    ll ans=0;

    for(int i=N-1;i>=0;i--){
        ll lhs=B[i]*sumA[i+1];
        ll rhs=A[i]*sumB[i+1];

        if(lhs>rhs){
            ans+=lhs;
        }else{
            ans+=rhs;
        }
    }
    cout<<ans<<endl;

}
0