結果

問題 No.198 キャンディー・ボックス2
ユーザー hokutohokuto
提出日時 2022-02-24 12:15:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,284 bytes
コンパイル時間 1,266 ms
コンパイル使用メモリ 121,708 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-15 06:49:25
合計ジャッジ時間 2,392 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,504 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,380 KB
testcase_25 WA -
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <cassert>
using namespace std;
using ll = long long int;
#define CHMAX(x,y)  (x) = ((x) > (y)) ? (x) : ((x) = (y));
#define CHMIN(x,y)  (x) = ((x) < (y)) ? (x) : ((x) = (y));
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define RREP(i,n,N) for(int (i)=(n);(i)<(N);++(i))
#define DREP(i,n) for(int (i)=(n);(i)>=0;--(i))
#define DRREP(i,n,N) for(int i=(n);(i)>=(N);--(i))
const int INF = 1e9;
const ll INFL = 1e18;
const int Mod = 1e9 + 7;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};


int main(int argc, char const *argv[])
{
  ll B,N; cin >> B >> N;
  vector<ll> C(N);
  REP(i,N)cin >> C[i];
  auto f = [&](ll K)->ll
  {
    ll res = 0;
    REP(i,N)res += abs(C[i]-K);
    return res;
  };
  sort(C.begin(),C.end());
  ll low = C[0],high = B; 
  REP(i,N)high += C[i];
  high = (high/N) + 1;

  ll cnt = 300;
  while(cnt--)
  {
    ll c1 = (2*low + high)/3;
    ll c2 = (low + 2*high)/3;
    if(f(c1) < f(c2))high = c2;
    else low = c1;
  }

  ll answer = INFL;
  RREP(i,low,high+1)CHMIN(answer,f(i));
  std::cout << answer << std::endl;
}
0