結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー aru aruaru aru
提出日時 2020-09-30 20:54:15
言語 Go
(1.22.1)
結果
RE  
実行時間 -
コード長 1,727 bytes
コンパイル時間 12,761 ms
コンパイル使用メモリ 203,300 KB
実行使用メモリ 5,544 KB
最終ジャッジ日時 2023-09-20 16:24:57
合計ジャッジ時間 17,391 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 9 ms
4,376 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 9 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 11 ms
5,536 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 9 ms
4,376 KB
testcase_33 RE -
testcase_34 WA -
testcase_35 AC 10 ms
4,376 KB
testcase_36 AC 11 ms
4,380 KB
testcase_37 RE -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 9 ms
4,376 KB
testcase_41 RE -
testcase_42 WA -
testcase_43 AC 8 ms
5,536 KB
testcase_44 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N, s, t := getInt(), getInt()-1, getInt()-1
	a := make([]int, N)
	tot := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		tot += a[i]
	}
	b := make([]int, 0, N*2)
	for i := t + 1; i < N; i++ {
		b = append(b, a[i])
	}
	for i := 0; i < t; i++ {
		b = append(b, a[i])
	}
	// out(a, tot)
	// out(b)
	pos := N - 1 - t + s
	n := (N - 2 + 1) / 2
	l := pos / 2
	r := (N-pos)/2 + pos - n
	// out("lr", l, r, pos, n)
	totS := 0
	for i := 0; i <= n; i++ {
		totS += b[i+l]
	}
	// out(totS, tot)
	ans := totS - (tot - totS)
	// out(ans)
	for i := l; i < r; i++ {
		totS += -b[i] + b[i+n+1]
		// out(totS, b[i], b[i+n+1])
		x := totS - (tot - totS)
		ans = max(ans, x)
		// out(totS - (tot - totS))
	}
	out(ans)
}
0