File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
8+ StringTokenizer st = new StringTokenizer (br. readLine());
9+
10+ int n = Integer . parseInt(st. nextToken());
11+ int l = Integer . parseInt(st. nextToken());
12+ int r = Integer . parseInt(st. nextToken());
13+ int x = Integer . parseInt(st. nextToken());
14+
15+ int [] a = new int [n];
16+ st = new StringTokenizer (br. readLine());
17+ for (int i = 0 ; i < n; i++ ) {
18+ a[i] = Integer . parseInt(st. nextToken());
19+ }
20+
21+ Arrays . sort(a);
22+
23+ int answer = 0 ;
24+
25+ for (int mask = 1 ; mask < (1 << n); mask++ ) {
26+ if (Integer . bitCount(mask) < 2 ) continue ;
27+
28+ int sum = 0 ;
29+ int min = Integer . MAX_VALUE ;
30+ int max = Integer . MIN_VALUE ;
31+
32+ for (int i = 0 ; i < n; i++ ) {
33+ if ((mask & (1 << i)) != 0 ) {
34+ sum += a[i];
35+ min = Math . min(min, a[i]);
36+ max = Math . max(max, a[i]);
37+ }
38+ }
39+
40+ if (sum >= l && sum <= r && max - min >= x) {
41+ answer++ ;
42+ }
43+ }
44+
45+ System . out. println(answer);
46+ }
47+ }
48+ ```
You can’t perform that action at this time.
0 commit comments