Skip to content

Commit 11c52f3

Browse files
committed
CF1419D2
1 parent 1921fe9 commit 11c52f3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

main/1400-1499/1419D2.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+
"sort"
8+
)
9+
10+
// github.com/EndlessCheng/codeforces-go
11+
func CF1419D2(_r io.Reader, _w io.Writer) {
12+
in := bufio.NewReader(_r)
13+
out := bufio.NewWriter(_w)
14+
defer out.Flush()
15+
16+
var n, ans int
17+
Fscan(in, &n)
18+
a := make([]int, n)
19+
for i := range a {
20+
Fscan(in, &a[i])
21+
}
22+
sort.Ints(a)
23+
b := make([]int, n)
24+
j := -1
25+
for _, v := range a {
26+
if j += 2; j >= n {
27+
j = 0
28+
}
29+
b[j] = v
30+
}
31+
for i := 1; i < n-1; i++ {
32+
if b[i] < b[i-1] && b[i] < b[i+1] {
33+
ans++
34+
}
35+
}
36+
Fprintln(out, ans)
37+
for _, v := range b {
38+
Fprint(out, v, " ")
39+
}
40+
}
41+
42+
//func main() { CF1419D2(os.Stdin, os.Stdout) }

main/1400-1499/1419D2_test.go

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

0 commit comments

Comments
 (0)