Skip to content

Commit a3e5454

Browse files
committed
CF1158A
1 parent 483656d commit a3e5454

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

main/1100-1199/1158A.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1158A(_r io.Reader, out io.Writer) {
11+
in := bufio.NewReader(_r)
12+
var n, m uint
13+
var v, ans, fi, se uint64
14+
for Fscan(in, &n, &m); n > 0; n-- {
15+
Fscan(in, &v)
16+
ans += v
17+
if v > fi {
18+
fi, se = v, fi
19+
} else if v > se {
20+
se = v
21+
}
22+
}
23+
ans = (ans - fi) * uint64(m)
24+
min := uint64(1e9)
25+
for ; m > 0; m-- {
26+
Fscan(in, &v)
27+
ans += v
28+
if v < min {
29+
min = v
30+
}
31+
}
32+
if fi > min {
33+
Fprint(out, -1)
34+
} else {
35+
if fi < min {
36+
ans += fi - se
37+
}
38+
Fprint(out, ans)
39+
}
40+
}
41+
42+
//func main() { CF1158A(os.Stdin, os.Stdout) }

main/1100-1199/1158A_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"github.com/EndlessCheng/codeforces-go/main/testutil"
5+
"testing"
6+
)
7+
8+
// https://codeforces.com/problemset/problem/1158/A
9+
// https://codeforces.com/problemset/status/1158/problem/A
10+
func TestCF1158A(t *testing.T) {
11+
// just copy from website
12+
rawText := `
13+
inputCopy
14+
3 2
15+
1 2 1
16+
3 4
17+
outputCopy
18+
12
19+
inputCopy
20+
2 2
21+
0 1
22+
1 0
23+
outputCopy
24+
-1
25+
inputCopy
26+
2 3
27+
1 0
28+
1 1 2
29+
outputCopy
30+
4`
31+
testutil.AssertEqualCase(t, rawText, 0, CF1158A)
32+
}

0 commit comments

Comments
 (0)