結果

問題 No.609 Noelちゃんと星々
ユーザー Naoyk1212
提出日時 2017-12-12 19:58:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 62,332 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-14 06:22:25
合計ジャッジ時間 2,610 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>

int main(){
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for(int i = 0; i < N; i++){
        std::cin >> v[i];
    }

    long long high = 1e9;
    long long low = -1e9;
    for(int i = 0; i < 100; i++){
        long long midu = (2 * high + low) / 3;
		long long midl = (high + 2 * low) / 3;

        long long cntu = 0;
		long long cntl = 0;
        for(int j = 0; j < N; j++){
            cntu += std::abs(v[j] - midu);
			cntl += std::abs(v[j] - midl);
        }
		
		if(cntl <= cntu)high = midu;
		else low = midl;
		std::cerr << low << " " << high << std::endl;
    }

    long long ans = 0;
    for(int i = 0; i < N; i++){
       ans += std::abs(v[i] - high); 
    }
    std::cout << ans << std::endl;
}
0