結果

問題 No.198 キャンディー・ボックス2
ユーザー omuomu
提出日時 2015-04-29 01:40:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,964 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 93,572 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 03:53:10
合計ジャッジ時間 3,831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
4,380 KB
testcase_01 AC 87 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 27 ms
4,376 KB
testcase_10 AC 27 ms
4,380 KB
testcase_11 AC 31 ms
4,376 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 16 ms
4,380 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 21 ms
4,380 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 30 ms
4,376 KB
testcase_19 AC 36 ms
4,376 KB
testcase_20 AC 41 ms
4,376 KB
testcase_21 AC 47 ms
4,380 KB
testcase_22 AC 52 ms
4,380 KB
testcase_23 WA -
testcase_24 AC 79 ms
4,376 KB
testcase_25 AC 81 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 84 ms
4,380 KB
testcase_29 AC 85 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:87:20: warning: ‘mid’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  for (target = mid - 1e6; target <= mid + 1e6; target++){
                ~~~~^~~~~

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define rall(a)		(a).rbegin(), (a).rend()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[9] = { -1, -1, -1, 0 , 0 , 0 , 1 , 1 , 1}, dy[9] = { -1, 0, 1 ,-1 , 0 , 1, -1 , 0,  1};
const int mod = 1000000007;
const ll INF = 1e15;

ll c[11];
ll b, n;
ll ave = 0;
ll target;

ll ok(){
	ll m = b;
	ll ret = 0;
	rep(i, n){
		if (c[i] > target){
			m += c[i] - target;
			ret += c[i] - target;
		}
	}
	rep(i, n){
		if (c[i] < target){
			m -= target - c[i];
			if (m < 0)return INF;
			ret += target - c[i];
		}
	}
	return ret;
}

int main()
{
	cin >> b;
	cin >> n;

	ll sum = 0;
	map<int, int> ma;
	rep(i, n){
		cin >> c[i];
		ma[c[i]]++;
		sum += c[i];
	}

	int mid;
	int Max = 0;
	for (auto i : ma){
		if (i.second > Max){
			mid = i.first;
			Max = i.second;
		}
	}
	int ave = sum/n;

	ll ans = INF;
	for (target = mid - 1e6; target <= mid + 1e6; target++){
		ans = min(ans, ok());
	}
	for (target = ave - 1e6; target <= ave + 1e6; target++){
		ans = min(ans, ok());
	}

	cout << ans << endl;

	return 0;
}
0