We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4988e1 commit 2da1527Copy full SHA for 2da1527
Contest/JOHNY.ml
@@ -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