Skip to content

Commit 2da1527

Browse files
author
coderxiang
committed
add a codechef problem
1 parent f4988e1 commit 2da1527

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Contest/JOHNY.ml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(* http://www.codechef.com/NOV13/problems/JOHNY/ *)
2+
let rec drop a n =
3+
match a with
4+
[] -> []
5+
| x :: xs -> if n <= 0 then a else drop xs (n - 1)
6+
7+
let next_int () = Scanf.scanf "%d " (fun x -> x)
8+
let n = next_int ()
9+
10+
let rec loop n f acc =
11+
if n = 0 then List.rev acc else loop (n-1) f ((f n) :: acc)
12+
13+
let solve t =
14+
let m = next_int () in
15+
let a = loop m (fun _ -> next_int ()) [] in
16+
let k = next_int () in
17+
let p = List.hd (drop a (k - 1)) in
18+
print_int (List.fold_left (fun acc x -> if x <= p then acc + 1 else acc) 0
19+
a); print_string "\n";
20+
1
21+
22+
let main =
23+
loop n solve []

0 commit comments

Comments
 (0)