結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー nanasili
提出日時 2015-04-29 00:25:27
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 792 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 891 ms
コンパイル使用メモリ 102,552 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-26 12:16:24
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <cctype>

using namespace std;

typedef long long ll;

int main() {
	int b;
	cin >> b;
	int n;
	cin >> n;
	ll sum = 0;
	int c[10];
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		sum += c[i];
	}
	int ans = 1000000000;
	ll l = 0, r = sum + b;
	for (int i = 0; i < 100; i++) {
		ll p = (l + r) / 2;
		ll t = 0;
		for (int i = 0; i < n; i++) {
			t += abs(c[i] - p);
		}
		if (t < ans) {
			r = p;
			ans = t;
		}else {
			l = p;
		}
	}
	cout << ans << endl;
}
0