← Home
For problem statement at 1000-1999/1700-1799/1760-1769/1765/problemF.txt this is a correct solution, but verifier at 1000-1999/1700-1799/1760-1769/1765/verifierF.go ends with All 41 tests passed. can you fix the verifier? package main

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

type Contract struct {
	x int64
	w int64
	c int64
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	var k int64
	if _, err := fmt.Fscan(reader, &n, &k); err != nil {
		return
	}

	contracts := make([]Contract, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &contracts[i].x, &contracts[i].w, &contracts[i].c)
	}

	sort.Slice(contracts, func(i, j int) bool {
		if contracts[i].x == contracts[j].x {
			return contracts[i].w < contracts[j].w
		}
		return contracts[i].x < contracts[j].x
	})

	dp := make([]int64, n)
	var maxProfit int64 = 0

	for i := 0; i < n; i++ {
		var bestPrev int64 = 0
		for j := 0; j < i; j++ {
			if contracts[j].x < contracts[i].x {
				profit := dp[j] + k*(contracts[j].c+contracts[i].c)*(contracts[i].x-contracts[j].x)
				if profit > bestPrev {
					bestPrev = profit
				}
			}
		}
		dp[i] = bestPrev - contracts[i].w*200
		if dp[i] > maxProfit {
			maxProfit = dp[i]
		}
	}

	fmt.Printf("%.15f\n", float64(maxProfit)/200.0)
}