結果
| 問題 | No.286 Modulo Discount Store |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-09 20:24:54 |
| 言語 | Go1.4 (1.4.2) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,400 bytes |
| 記録 | |
| コンパイル時間 | 321 ms |
| コンパイル使用メモリ | 34,816 KB |
| 最終ジャッジ日時 | 2025-12-03 10:26:36 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 2 TLE * 1 -- * 37 |
ソースコード
package main
import (
"fmt"
)
import (
"bufio"
"os"
"strconv"
"sort"
)
func main() {
N := nextInt()
var data = make([]int, N)
for i := 0; i < N; i++ {
data[i] = nextInt()
}
sort.Ints(data)
minBuyTotal := N * 10000
for {
buy := 0
priceTotal := 0
for i := 0; i < N; i++ {
buy+=data[i]-min(data[i], priceTotal%1000)
priceTotal+=data[i]
}
minBuyTotal = min(minBuyTotal, buy)
if !next_permutation(data) {
break
}
}
fmt.Println(minBuyTotal)
}
func next_permutation(a []int) bool {
for i := len(a) - 2; i >= 0; i-- {
if a[i] < a[i+1] {
for j := len(a) - 1; j >= 0; j-- {
if a[j] >= a[i] {
a[i], a[j] = a[j], a[i]
reverse(a, i+1, len(a)-(i+1))
return true
}
}
}
}
reverse(a, 0, len(a))
return false
}
func reverse(a []int, start int, length int) {
var end = start + length - 1
for start < end {
a[start], a[end] = a[end], a[start]
start++
end--
}
}
var s = bufio.NewScanner(os.Stdin)
func min(a int, b int) int {
if a < b {
return a
}
return b
}
func next() string {
s.Split(bufio.ScanWords)
s.Scan()
return s.Text()
}
func nextLine() string {
s.Split(bufio.ScanLines)
s.Scan()
return s.Text()
}
func nextInt() int {
i, e := strconv.Atoi(next())
if e != nil {
panic(e)
}
return i
}
func nextLong() int64 {
i, e := strconv.ParseInt(next(), 10, 64)
if e != nil {
panic(e)
}
return i
}