結果

問題 No.2248 max(C)-min(C)
ユーザー bayashikobayashiko
提出日時 2023-03-06 22:20:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,106 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 205,140 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2023-10-18 05:18:33
合計ジャッジ時間 5,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,348 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 49 ms
6,764 KB
testcase_21 AC 47 ms
6,604 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 44 ms
6,444 KB
testcase_28 AC 6 ms
4,348 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 11 ms
4,348 KB
testcase_33 AC 17 ms
4,608 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 27 ms
5,264 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
//#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define MINF (lint)(2e18)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
//#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
//typedef __int128_t llint;
//#include<atcoder/all>
//using namespace atcoder;

int main(void){
    lint N;
    cin >> N;
    lint A[N],B[N];
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    lint sum=0;
    rep(i,N) sum+=A[i],sum+=B[i];
    rep(i,N) if(A[i]>B[i]) swap(A[i],B[i]);
    lint maxi=-1e18,mini=1e18;
    rep(i,N){
        lint dis[3];
        dis[0]=abs(sum-A[i]*2*N);
        dis[1]=abs(sum-(A[i]+B[i])*2);
        dis[2]=abs(sum-B[i]*2*N);
        lint take=min_element(dis,dis+3)-dis;
        if(take==0){
            chmax(maxi,A[i]);
            chmin(mini,A[i]);
        }
        else if(take==1){
            chmax(maxi,(A[i]+B[i])/2);
            chmin(mini,(A[i]+B[i])/2);
        }
        else{
            chmax(maxi,B[i]);
            chmin(mini,B[i]);
        }
    }
    cout << maxi-mini << endl;
}
0