結果

問題 No.2217 Suffix+
ユーザー HimaHima
提出日時 2023-03-02 20:27:30
言語 Go
(1.22.1)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 17,580 ms
コンパイル使用メモリ 214,260 KB
実行使用メモリ 9,844 KB
最終ジャッジ日時 2023-10-17 16:32:41
合計ジャッジ時間 16,475 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,604 KB
testcase_01 AC 2 ms
5,604 KB
testcase_02 AC 2 ms
5,604 KB
testcase_03 AC 2 ms
5,604 KB
testcase_04 AC 2 ms
5,604 KB
testcase_05 AC 2 ms
5,604 KB
testcase_06 AC 2 ms
5,604 KB
testcase_07 AC 1 ms
5,604 KB
testcase_08 AC 2 ms
5,604 KB
testcase_09 AC 1 ms
5,604 KB
testcase_10 AC 2 ms
5,604 KB
testcase_11 AC 2 ms
5,604 KB
testcase_12 AC 2 ms
5,604 KB
testcase_13 AC 2 ms
5,604 KB
testcase_14 AC 5 ms
5,736 KB
testcase_15 AC 5 ms
5,736 KB
testcase_16 AC 8 ms
5,740 KB
testcase_17 AC 7 ms
5,740 KB
testcase_18 AC 6 ms
5,740 KB
testcase_19 AC 47 ms
7,792 KB
testcase_20 AC 46 ms
7,792 KB
testcase_21 AC 11 ms
5,736 KB
testcase_22 AC 46 ms
7,792 KB
testcase_23 AC 43 ms
5,740 KB
testcase_24 AC 19 ms
7,796 KB
testcase_25 AC 18 ms
7,796 KB
testcase_26 AC 18 ms
7,796 KB
testcase_27 AC 17 ms
7,796 KB
testcase_28 AC 17 ms
7,796 KB
testcase_29 AC 69 ms
7,796 KB
testcase_30 AC 70 ms
7,796 KB
testcase_31 AC 70 ms
7,796 KB
testcase_32 AC 72 ms
7,796 KB
testcase_33 AC 72 ms
7,796 KB
testcase_34 AC 19 ms
9,844 KB
testcase_35 AC 1 ms
5,604 KB
testcase_36 AC 97 ms
7,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	//bufサイズ以上の文字列入力が必要な場合は拡張すること
	buf := make([]byte, 9*1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()
	a := nextIntSlice(n)
	ans := solve(n, k, a)
	PrintInt(ans)
}

func solve(n, k int, a []int) int {
	min := a[0]
	for _, v := range a {
		min = Min(min, v)
	}
	check := func(x int) bool {
		offset := 0
		cnt := 0
		for i, v := range a {
			diff := x - (v + offset)
			//すでにa_iは目標x以上
			if diff <= 0 {
				continue
			}
			c := Ceil(diff, i+1)
			cnt += c
			offset += c * (i + 1)
		}
		return cnt <= k
	}
	ok, ng := min, int(1e15)
	for ng-ok > 1 {
		mid := (ok + ng) / 2
		if check(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	return ok
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

func nextIntSlice(n int) []int {
	s := make([]int, n)
	for i := range s {
		s[i] = nextInt()
	}
	return s
}

func PrintInt(x int) {
	defer out.Flush()
	fmt.Fprintln(out, x)
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func Ceil(x, y int) int {
	return (x + y - 1) / y
}
0