結果
問題 |
No.198 キャンディー・ボックス2
|
ユーザー |
![]() |
提出日時 | 2015-05-05 00:21:12 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,854 bytes |
コンパイル時間 | 894 ms |
コンパイル使用メモリ | 108,544 KB |
実行使用メモリ | 18,944 KB |
最終ジャッジ日時 | 2024-07-05 19:02:39 |
合計ジャッジ時間 | 2,607 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 WA * 11 |
コンパイルメッセージ
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.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace No198 { class Program { static void Main(string[] args) { var hand = long.Parse(Console.ReadLine()); var n = long.Parse(Console.ReadLine()); var data = new long[n]; for (int i = 0; i < n; i++) { data[i] = long.Parse(Console.ReadLine()); } var sum = hand + data.Sum(); long minValue = 0; long maxValue = sum/n; while (maxValue - minValue > 1) { var minOperation = Calculate(data, minValue); var middleValue = (minValue + maxValue) / 2; var middleOperation = Calculate(data, middleValue); var maxOperation = Calculate(data, maxValue); var currentMin = new[] {minOperation, middleOperation, maxOperation}.Min(); if (currentMin == middleOperation) { if (minOperation < maxOperation) { maxValue = middleValue; } else { minValue = middleValue; } } else { break; } } var result = Math.Min(Calculate(data, minValue), Calculate(data, maxValue)); Console.WriteLine(result); } private static long Calculate(long[] data, long lastValue) { var operations = data.Select(element => Math.Abs(element - lastValue)).Sum(); return operations; } } }