結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2018-10-04 10:11:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,201 bytes |
コンパイル時間 | 2,075 ms |
コンパイル使用メモリ | 112,280 KB |
実行使用メモリ | 75,408 KB |
最終ジャッジ日時 | 2024-10-12 11:12:05 |
合計ジャッジ時間 | 4,652 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | RE * 2 TLE * 1 -- * 23 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var b = int.Parse(Console.ReadLine().Trim()); var n = int.Parse(Console.ReadLine().Trim()); var a = new int[n]; var amax = 0; var amin = int.MaxValue; var asum = 0; for (int i = 0; i < n; i++) { a[i] = int.Parse(Console.ReadLine().Trim()); amax = Math.Max(amax, a[i]); amin = Math.Min(amin, a[i]); asum += a[i]; } var ans = new List<int>(); for (int i = amin; i <= amax; i++) { var w = getAns(a, b, asum, n, i); if (w != -1) ans.Add(w); } Console.WriteLine(ans.Min()); } public static int getAns(int[] a, int b, int asum, int n, int t) { if (asum + b < t * n) return -1; if (asum + b == t * n) { var c = a.Where(x => x - t > 0).Select(x => x - t).Sum(); return b + c * 2; } var cm = a.Where(x => x - t < 0).Select(x => x - t).Sum(); var cp = a.Where(x => x - t > 0).Select(x => x - t).Sum(); return cp - cm; } }