Skip to content

Commit 456260e

Browse files
committed
CF1401B
1 parent 4f50bc8 commit 456260e

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

main/1400-1499/1401B.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
)
8+
9+
// github.com/EndlessCheng/codeforces-go
10+
func CF1401B(_r io.Reader, _w io.Writer) {
11+
in := bufio.NewReader(_r)
12+
out := bufio.NewWriter(_w)
13+
defer out.Flush()
14+
min := func(a, b int) int {
15+
if a > b {
16+
return b
17+
}
18+
return a
19+
}
20+
21+
var T, a, b, c, x, y, z int
22+
for Fscan(in, &T); T > 0; T-- {
23+
Fscan(in, &a, &b, &c, &x, &y, &z)
24+
ans := min(c, y) * 2
25+
cnt := c - min(c, y) + a
26+
if cnt < z {
27+
ans -= (z - cnt) * 2
28+
}
29+
Fprintln(out, ans)
30+
}
31+
}
32+
33+
//func main() { CF1401B(os.Stdin, os.Stdout) }

main/1400-1499/1401B_test.go

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

0 commit comments

Comments
 (0)