File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
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) }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments