結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-03 12:01:39 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,866 bytes |
| コンパイル時間 | 1,062 ms |
| コンパイル使用メモリ | 118,188 KB |
| 実行使用メモリ | 33,780 KB |
| 最終ジャッジ日時 | 2024-10-05 03:27:20 |
| 合計ジャッジ時間 | 4,460 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 TLE * 1 -- * 13 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
long temotiCount = long.Parse(Reader.ReadLine());
int boxCount = int.Parse(Reader.ReadLine());
List<long> boxList = new List<long>();
Dictionary<long, int> dic = new Dictionary<long, int>();
long total = 0;
for(int i=0; i<boxCount; i++) {
long val = long.Parse(Reader.ReadLine());
if(dic.ContainsKey(val)) {
dic[val]++;
} else
{
dic.Add(val, 1);
}
boxList.Add(val);
total += val;
}
long heikin = total / boxCount;
if(Math.Abs(total - (heikin + 1) * boxCount) < Math.Abs(total - heikin * boxCount)) {
heikin++;
}
while ((total - heikin * boxCount) > temotiCount)
{
heikin--;
}
// 最頻値
List<long> modeList = new List<long>();
int prevCnt = dic.Max(a=>a.Value);
dic.ToList().ForEach((a)=>{
if(a.Value == prevCnt && total + temotiCount >= a.Key * boxCount) {
modeList.Add(a.Key);
}
});
long ans = long.MaxValue;
long tmp = 0;
boxList.ForEach((a)=>{
tmp += Math.Abs(a - heikin);
});
ans = Math.Min(ans, tmp);
modeList.ForEach((a)=>{
tmp = 0;
boxList.ForEach((b)=>{
tmp+=Math.Abs(a-b);
});
ans = Math.Min(ans, tmp);
});
Console.WriteLine(ans);
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
1000000000
1
1000000000
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
public static int[] GetInt(char delimiter = ' ', bool trim = false)
{
string inptStr = ReadLine();
if (trim)
{
inptStr = inptStr.Trim();
}
string[] inpt = inptStr.Split(delimiter);
int[] ret = new int[inpt.Length];
for (int i = 0; i < inpt.Length; i++)
{
ret[i] = int.Parse(inpt[i]);
}
return ret;
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番