-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONTEST_31_Subset_Sum.clj
32 lines (27 loc) · 1.04 KB
/
CONTEST_31_Subset_Sum.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(comment "
ques link -https://www.hackerrank.com/contests/int213-contest31/challenges/subset-sum/leaderboard
}
}
")
(require '[clojure.data.int-map :as i])
(let [N (Integer/parseInt (read-line))
A (map #(Long/parseLong %) (.split (read-line) " "))
sortedA (reverse (sort A))
partials (reductions + sortedA)
tops (last partials)
T (Integer/parseInt (read-line))
cases (for [_ (range T)] (Long/parseLong (read-line)))
posmap (loop [pos 1
[case1 & caser :as cases] (sort cases)
[part1 & partr :as partials] partials
posmap (i/int-map)]
(cond
(nil? case1) posmap
(> case1 tops)
(recur pos caser partials posmap)
(>= part1 case1)
(recur pos caser partials
(assoc posmap case1 pos))
true (recur (inc pos) cases partr posmap)))]
(doseq [case cases]
(println (get posmap case -1))))