Skip to content

Commit 4e16fe8

Browse files
committed
CF605A
1 parent cab852b commit 4e16fe8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

main/600-699/605A.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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) }

main/600-699/605A_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

0 commit comments

Comments
 (0)