File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-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
+ )
8
+
9
+ // github.com/EndlessCheng/codeforces-go
10
+ func CF605A (_r io.Reader , out io.Writer ) {
11
+ in := bufio .NewReader (_r )
12
+ var n , v , ans int
13
+ Fscan (in , & n )
14
+ p := make ([]int , n )
15
+ for i := 0 ; i < n ; i ++ {
16
+ Fscan (in , & v )
17
+ p [v - 1 ] = i
18
+ }
19
+ for i := 0 ; i < n ; {
20
+ st := i
21
+ for i ++ ; i < n && p [i ] > p [i - 1 ]; i ++ {
22
+ }
23
+ if i - st > ans {
24
+ ans = i - st
25
+ }
26
+ }
27
+ Fprint (out , n - ans )
28
+ }
29
+
30
+ //func main() { CF605A(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/605/A
9
+ // https://codeforces.com/problemset/status/605/problem/A
10
+ func TestCF605A (t * testing.T ) {
11
+ // just copy from website
12
+ rawText := `
13
+ inputCopy
14
+ 5
15
+ 4 1 2 5 3
16
+ outputCopy
17
+ 2
18
+ inputCopy
19
+ 4
20
+ 4 1 3 2
21
+ outputCopy
22
+ 2`
23
+ testutil .AssertEqualCase (t , rawText , 0 , CF605A )
24
+ }
You can’t perform that action at this time.
0 commit comments