Introduction

取餐排隊 Food lines

https://dmoj.ca/problem/lkp18c2p1

package main

import "fmt"

// https://dmoj.ca/problem/lkp18c2p1
const (
    maxLines = 100
)

func ShortestLineIndex(lines []int, n int) int {
    shortest := 0
    for i := 0; i < n; i++ {
        if lines[i] < lines[shortest] {
            shortest = i
        }
    }

    return shortest
}

func solve(lines []int, n int, m int) {
    for i := 0; i < m; i++ {
        shortest := ShortestLineIndex(lines, n)
        fmt.Println(lines[shortest])
        lines[shortest]++
    }
}

func main() {
    var n, m int
    fmt.Scan(&n, &m)
    lines := make([]int, maxLines)
    // lines := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&lines[i])
    }
    solve(lines, n, m)
}
© Kimi Tsai all right reserved.            Updated : 2023-07-12 09:04:53

results matching ""

    No results matching ""

    results matching ""

      No results matching ""