結果

問題 No.999 てん vs. ほむ
ユーザー hidajun
提出日時 2020-03-04 09:05:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 657 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 167,720 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 23:31:44
合計ジャッジ時間 3,627 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main(){
    ll n,ans = 0,sum=0;
    cin >> n;
    VLL a(2*n);

    rep(i,2*n)cin >> a[i];

    ll l = 0, r = 2*n -1, ls = a[0]-a[1], rs = a[2*n-1] - a[2*n -2];

    while(sum != 2*n){
        if(ls > rs){
            ans += ls;
            l += 2;
            ls = a[l] - a[l+1];
            sum += 2;
        }else{
            ans += rs;
            r -= 2;
            rs = a[r] - a[r-1];
            sum += 2;
        }
    }

    cout << ans << endl;
}
0