結果

問題 No.972 選び方のスコア
ユーザー SugihaMSugihaM
提出日時 2020-04-22 14:07:29
言語 Go
(1.22.1)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 14,701 ms
コンパイル使用メモリ 210,272 KB
実行使用メモリ 5,496 KB
最終ジャッジ日時 2023-08-01 15:39:42
合計ジャッジ時間 21,258 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
5,496 KB
testcase_01 AC 65 ms
5,492 KB
testcase_02 AC 65 ms
5,488 KB
testcase_03 AC 32 ms
5,468 KB
testcase_04 AC 65 ms
5,496 KB
testcase_05 AC 63 ms
5,492 KB
testcase_06 AC 63 ms
5,492 KB
testcase_07 AC 49 ms
5,480 KB
testcase_08 AC 28 ms
5,496 KB
testcase_09 AC 27 ms
5,492 KB
testcase_10 AC 27 ms
5,492 KB
testcase_11 AC 28 ms
5,492 KB
testcase_12 AC 29 ms
5,492 KB
testcase_13 AC 29 ms
5,492 KB
testcase_14 AC 29 ms
5,492 KB
testcase_15 AC 32 ms
5,496 KB
testcase_16 AC 31 ms
5,492 KB
testcase_17 AC 31 ms
5,492 KB
testcase_18 AC 2 ms
4,328 KB
testcase_19 AC 65 ms
5,496 KB
testcase_20 AC 63 ms
5,492 KB
testcase_21 AC 66 ms
5,492 KB
testcase_22 AC 60 ms
5,488 KB
testcase_23 AC 62 ms
5,492 KB
testcase_24 AC 62 ms
5,496 KB
testcase_25 AC 1 ms
4,332 KB
testcase_26 AC 1 ms
4,332 KB
testcase_27 AC 1 ms
4,328 KB
testcase_28 AC 1 ms
4,332 KB
testcase_29 AC 1 ms
4,332 KB
testcase_30 AC 1 ms
4,328 KB
testcase_31 AC 1 ms
4,328 KB
testcase_32 AC 1 ms
4,332 KB
testcase_33 AC 1 ms
4,332 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}
func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 100000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(Scanner())
	}

	sort.Ints(a)

	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		sum[i+1] = a[i]
		sum[i+1] += sum[i]
	}

	ans := 0
	b := 0
	c := 0
	d := 0
	for i := 1; i < n-1; i++ {
		b = 0
		c = min(i, n-i-1) + 1
		for c-b > 1 {
			d = (b + c) / 2
			if a[i-d]+a[n-d]-2*a[i] > 0 {
				b = d
			} else {
				c = d
			}
		}
		ans = max(ans, sum[i]-sum[i-b]+sum[n]-sum[n-b]-a[i]*(2*b))
	}
	fmt.Println(ans)
}

func min(x int, y int) int {
	if x >= y {
		return y
	} else {
		return x
	}
}

func max(x int, y int) int {
	if x >= y {
		return x
	} else {
		return y
	}
}
0