I tried Atcoder, so it's a memo for myself. I plan to add and correct it later.
https://atcoder.jp/contests/abc188
A
Q_A.go
package main
import (
"fmt"
)
func main() {
var X, Y int
fmt.Scanf("%d %d", &X, &Y)
var flag bool = false
if X>Y{
if X-Y < 3{
flag = true
}
} else {
if Y-X < 3{
flag = true
}
}
if flag{
fmt.Printf("Yes\n")
} else {
fmt.Printf("No\n")
}
}
B
Q_B.go
package main
import (
"fmt"
)
func main() {
var N int
fmt.Scanf("%d", &N)
var sum int64 = 0
A := make([]int64, N)
B := make([]int64, N)
for i:=0; i<N; i++{
fmt.Scanf("%d", &A[i])
}
for i:=0; i<N; i++{
fmt.Scanf("%d", &B[i])
}
for i:=0; i<N; i++{
sum += A[i] * B[i]
}
if sum == 0{
fmt.Printf("Yes\n")
} else {
fmt.Printf("No\n")
}
}
C
Q_C.go
package main
import (
"fmt"
)
func main() {
var N int
fmt.Scanf("%d", &N)
var imax int = 1
for i:=0; i<N; i++{
imax *= 2
}
A := make([]int64, imax)
for i:=0; i<imax; i++{
fmt.Scanf("%d", &A[i])
}
var left int64 = 0
var left_index int
for i:=0; i<imax/2; i++{
if left < A[i]{
left = A[i]
left_index = i
}
}
var right int64 = 0
var right_index int
for i:=imax/2; i<imax; i++{
if right < A[i]{
right = A[i]
right_index = i
}
}
if left > right{
fmt.Printf("%d\n", right_index+1)
} else {
fmt.Printf("%d\n", left_index+1)
}
}
D
Q_D.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 int64
var C int64
N = nextInt()
C = nextInt()
a := make([]int64, N)
b := make([]int64, N)
c := make([]int64, N)
var amin int64 = 1000000000
var bmax int64 = 1
var i int64
for i=0; i<N; i++ {
a[i] = nextInt()
b[i] = nextInt()
c[i] = nextInt()
if amin > a[i]{
amin = a[i]
}
if bmax < b[i]{
bmax = b[i]
}
}
index := make(map[int64]int64)
for i=0; i<N; i++{
index[a[i]] = index[a[i]] + c[i]
index[b[i]+1] = index[b[i]+1] - c[i]
}
keys := make([]int64, 0, len(index))
for k := range index {
keys = append(keys, k)
}
sort.Slice(keys, func(s, t int) bool {
return keys[s] < keys[t]
})
var cost_sum int64 = 0
var sum int64 = 0
var before int64 = 0
for i:=0; i<len(index); i++{
//Add to the front
if cost_sum > C{
sum += C * (keys[i] - before)
} else {
sum += cost_sum * (keys[i] - before)
}
// tugiwo keisann
cost_sum = cost_sum + index[keys[i]]
before = keys[i]
}
fmt.Printf("%d\n", sum)
}
E If you remember, I will write it later.
F If you remember, I will write it later.
Recommended Posts