結果

問題 No.489 株に挑戦
ユーザー いともたやすく行われるえげつない行為いともたやすく行われるえげつない行為
提出日時 2017-02-25 19:06:06
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 1,675 bytes
コンパイル時間 12,470 ms
コンパイル使用メモリ 202,264 KB
実行使用メモリ 19,488 KB
最終ジャッジ日時 2023-09-02 08:06:14
合計ジャッジ時間 16,627 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #E
// yukicoder no.489 main.go
package main

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

type mock struct {
	day   int
	value int
}

func searching(data1, data2 []mock, window int) (int, int, int) {
	max, buy, sell := int(-1e9), -1, -1

	for high := range data2 {
		for low := range data1 {
			if data2[high].value <= data1[low].value {
				break
			}

			if data1[low].day < data2[high].day &&
				data2[high].day <= data1[low].day+window {
				tmp := data2[high].value - data1[low].value

				if max == tmp {
					if data1[low].day == buy {
						if data2[high].day < sell {
							sell = data2[high].day
							continue
						}
					}
					if data1[low].day < buy {
						buy, sell = data1[low].day, data2[high].day

					}
				}
				if max < tmp {
					max, buy, sell = tmp, data1[low].day, data2[high].day
				}
			}
		}
	}

	return max, buy, sell
}

func solve(in io.Reader, out, err io.Writer) {
	day, window, origin := 0, 0, 0
	value, buy, sell := 0, 0, 0

	fmt.Fscan(in, &day, &window, &origin)
	data1 := make([]mock, day)
	data2 := make([]mock, day)
	for i := range data1 {
		temp := 0
		fmt.Fscan(in, &temp)
		data1[i].day = i
		data1[i].value = temp
		data2[i].day = i
		data2[i].value = temp
	}

	sort.Slice(data1, func(i, j int) bool {
		return data1[i].value < data1[j].value
	})
	sort.Slice(data2, func(i, j int) bool {
		return data2[i].value > data2[j].value
	})

	tempV, buy, sell := searching(data1, data2, window)

	if tempV < 0 {
		tempV = 0
	}
	value = origin * tempV

	fmt.Fprintln(out, value)
	if value != 0 {
		fmt.Fprintln(out, buy, sell)
	}
}

func main() {
	br := bufio.NewReaderSize(os.Stdin, int(1e7))
	solve(br, os.Stdout, os.Stderr)
}
0