I tried Atcoder, so it's a memo for myself. I plan to add and correct it later.
https://atcoder.jp/contests/keyence2021
A
Q_A.go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func nextInt() int64 {
sc.Scan()
i, e := strconv.ParseInt(sc.Text(),10,64)
if e != nil {
panic(e)
}
return i
}
func main() {
sc.Split(bufio.ScanWords)
var N int
fmt.Scanf("%d", &N)
var a int64
var c int64
b := make([]int64, N)
d := make([]int64, N)
a = nextInt()
d[0] = a
for i:=1; i<N; i++ {
a = nextInt()
if d[i-1] > a{
d[i] = d[i-1]
} else {
d[i] = a
}
}
for i:=0; i<N; i++ {
b[i] = nextInt()
}
c = d[0] * b[0]
fmt.Printf("%d\n", c)
for i:=1; i<N; i++{
if d[i] * b[i] > c{
c = d[i] * b[i]
} else {
c = c
}
fmt.Printf("%d\n", c)
}
}
B
Q_B.go
package main
import (
"bufio"
"fmt"
"sort"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func nextInt() int64 {
sc.Scan()
i, e := strconv.ParseInt(sc.Text(),10,64)
if e != nil {
panic(e)
}
return i
}
func main() {
sc.Split(bufio.ScanWords)
var N, K int
fmt.Scanf("%d %d", &N, &K)
a := make([]int64, N)
box := make([]int64, K)
for i:=0; i<N; i++{
a[i] = nextInt()
}
sort.Slice(a, func(i, j int) bool {
return a[i] < a[j]
})
var j int = 0
var tmp int64 = -1
for i:=0; i<N; i++{
if a[i] == tmp{
if box[j] == a[i]{
box[j] = a[i]+1
}
if j+1 < K{
j = j+1
}
} else {
if box[0] == a[i]{
box[0] = a[i]+1
}
tmp = a[i]
if 1 < K{
j = 1
}
}
}
var sum int64
for i:=0; i<K; i++{
sum += box[i]
}
fmt.Printf("%d\n", sum)
}
C If you remember, I will write it later.
D If you remember, I will write it later.
E If you remember, I will write it later.
F If you remember, I will write it later.
Recommended Posts