結果

問題 No.1071 ベホマラー
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-05 23:54:26
言語 Go
(1.22.1)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,801 bytes
コンパイル時間 17,899 ms
コンパイル使用メモリ 211,500 KB
実行使用メモリ 5,492 KB
最終ジャッジ日時 2023-08-22 18:33:02
合計ジャッジ時間 15,308 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 53 ms
5,488 KB
testcase_11 AC 50 ms
5,492 KB
testcase_12 AC 32 ms
4,376 KB
testcase_13 AC 45 ms
5,488 KB
testcase_14 AC 57 ms
5,488 KB
testcase_15 AC 65 ms
5,488 KB
testcase_16 AC 64 ms
5,488 KB
testcase_17 AC 65 ms
5,488 KB
testcase_18 AC 64 ms
5,484 KB
testcase_19 AC 64 ms
5,484 KB
testcase_20 AC 15 ms
5,484 KB
testcase_21 AC 15 ms
5,484 KB
testcase_22 AC 15 ms
5,488 KB
testcase_23 AC 15 ms
5,484 KB
testcase_24 AC 51 ms
5,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 1
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		cnt = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	for i := 0; i < cnt; i++ {
		if i > 0 {
			fmt.Fprintln(writer, "-----------------------------------")
		}
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt64(scanner)
	x := getNextInt64(scanner)
	y := getNextInt64(scanner)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[i] = count(getNextInt64(scanner)-1, k)
	}
	sort.SliceStable(aa, func(i, j int) bool {
		return aa[i] < aa[j]
	})
	var m, r int64
	for i := 0; i < n; i++ {
		if int64(n-i)*x >= y {
			r = aa[i]
			continue
		}
		m += (aa[i] - r) * x
	}
	fmt.Fprintln(writer, m+r*y)
}
func count(a, k int64) int64 {
	return (a + k - 1) / k
}
func heal(a, k, x, y, c int64) int64 {
	if a-k*c <= 0 {
		return 0
	}
	return count(a-k*c, k) * x
}
0