Submission details
Task:Skyline
Sender:aalto26hw_002
Submission time:2026-10-28 17:41:50 +0200
Language:Java
Status:READY
Result:
Test results
testverdicttime
#10.05 sdetails
#20.05 sdetails
#30.05 sdetails
#40.05 sdetails
#50.05 sdetails
#60.05 sdetails
#70.05 sdetails
#80.05 sdetails
#90.05 sdetails
#100.05 sdetails
#110.05 sdetails
#120.05 sdetails
#130.05 sdetails
#140.05 sdetails
#150.05 sdetails
#160.05 sdetails
#170.05 sdetails
#180.05 sdetails
#190.05 sdetails
#200.05 sdetails
#210.05 sdetails
#220.05 sdetails
#230.05 sdetails
#240.05 sdetails
#250.05 sdetails
#260.05 sdetails
#270.05 sdetails
#280.05 sdetails
#290.05 sdetails
#300.05 sdetails
#310.06 sdetails
#320.06 sdetails
#330.06 sdetails
#340.06 sdetails
#350.06 sdetails
#360.06 sdetails
#370.06 sdetails
#380.06 sdetails
#390.06 sdetails
#400.06 sdetails
#410.06 sdetails
#420.06 sdetails
#430.06 sdetails
#440.06 sdetails
#450.06 sdetails
#460.06 sdetails
#470.06 sdetails
#480.06 sdetails
#490.06 sdetails
#500.06 sdetails
#510.14 sdetails
#520.14 sdetails
#530.14 sdetails
#540.14 sdetails

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Skyline {
    public static void main(String[] args) {
        FastScanner input = new FastScanner(System.in);
        int n = input.nextInt();
        int q = input.nextInt();

        int[] rocks = new int[n];
        for (int i = 0; i < n; i++){
            rocks[i] = input.nextInt();
        }

        int[] towers = new int[n];
        for (int i = 0; i < q; i++){
            towers[i] = input.nextInt();
        }

        for (int i = 0; i < q; i++){
            Boolean isSum = isSubsetSum(rocks, n, towers[i]);
            if (isSum){
                System.out.print("Yes ");
            } else {
                System.out.print("No ");
            }
        }
    }

    static boolean isSubsetSum(int set[], int n, int sum)
    {
        // Base Cases
        if (sum == 0)
            return true;
        if (n == 0)
            return false;

        // If last element is greater than
        // sum, then ignore it
        if (set[n - 1] > sum)
            return isSubsetSum(set, n - 1, sum);

        // Else, check if sum can be obtained
        // by any of the following
        // (a) including the last element
        // (b) excluding the last element
        return isSubsetSum(set, n - 1, sum)
            || isSubsetSum(set, n - 1, sum - set[n - 1]);
    }

    static class FastScanner { //static class fastScanner
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
    	 return Double.parseDouble(next());
	 }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}
}

Test details

Test 1

Verdict:

input
1 20
8 
29 43 23 70 56 72 72 50 43 79 ...

correct output
No No No No No No No No No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
	at Skyline.main(Skyline.java:20)

Test 2

Verdict:

input
2 20
8 8 
6 38 42 31 55 41 90 8 74 92 72...

correct output
No No No No No No No Yes No No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
	at Skyline.main(Skyline.java:20)

Test 3

Verdict:

input
2 20
8 10 
67 92 41 94 85 41 87 67 71 1 2...

correct output
No No No No No No No No No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
	at Skyline.main(Skyline.java:20)

Test 4

Verdict:

input
3 20
8 8 10 
58 60 46 57 39 26 28 19 67 99 ...

correct output
No No No No No Yes No No No No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
	at Skyline.main(Skyline.java:20)

Test 5

Verdict:

input
3 20
1 7 8 
30 69 38 80 10 38 83 43 83 65 ...

correct output
No No No No No No No No No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
	at Skyline.main(Skyline.java:20)

Test 6

Verdict:

input
3 20
10 4 3 
83 7 5 38 11 99 60 10 53 61 42...

correct output
No Yes No No No No No Yes No N...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
	at Skyline.main(Skyline.java:20)

Test 7

Verdict:

input
4 20
1 9 5 2 
18 36 87 78 99 50 94 76 29 43 ...

correct output
No No No No No No No No No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
	at Skyline.main(Skyline.java:20)

Test 8

Verdict:

input
4 20
1 7 4 7 
79 78 78 48 66 96 96 100 6 84 ...

correct output
No No No No No No No No No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
	at Skyline.main(Skyline.java:20)

Test 9

Verdict:

input
4 20
8 10 8 2 
22 50 48 68 61 28 20 26 95 53 ...

correct output
No No No No No Yes Yes Yes No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
	at Skyline.main(Skyline.java:20)

Test 10

Verdict:

input
4 20
6 1 9 10 
16 91 9 41 27 20 58 31 19 20 9...

correct output
Yes No Yes No No Yes No No Yes...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
	at Skyline.main(Skyline.java:20)

Test 11

Verdict:

input
5 20
6 8 9 7 9 
55 85 43 63 65 39 44 30 90 6 9...

correct output
No No No No No Yes No Yes No Y...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 12

Verdict:

input
5 20
10 8 10 1 2 
31 100 15 24 10 40 19 39 35 67...

correct output
Yes No No No Yes No Yes No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 13

Verdict:

input
5 20
2 1 10 6 10 
44 49 43 33 34 16 21 70 62 12 ...

correct output
No No No No No Yes Yes No No Y...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 14

Verdict:

input
5 20
1 8 9 3 2 
52 57 90 44 90 2 13 5 21 25 6 ...

correct output
No No No No No Yes Yes Yes Yes...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 15

Verdict:

input
5 20
10 6 2 10 9 
72 61 70 60 22 15 98 23 1 70 2...

correct output
No No No No Yes Yes No No No N...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 16

Verdict:

input
5 20
2 10 10 4 4 
92 98 49 9 62 40 77 36 52 49 3...

correct output
No No No No No No No No No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 17

Verdict:

input
5 20
10 4 3 9 1 
5 38 11 99 60 10 53 61 42 54 3...

correct output
Yes No Yes No No Yes No No No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 18

Verdict:

input
5 20
4 8 4 6 10 
73 46 98 31 54 27 51 9 8 42 27...

correct output
No No No No No No No No Yes No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 19

Verdict:

input
5 20
1 10 3 9 4 
54 82 24 43 2 62 44 77 41 41 5...

correct output
No No Yes No No No No No No No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 20

Verdict:

input
5 20
4 6 6 6 2 
14 32 15 2 22 88 42 14 25 14 9...

correct output
Yes No No Yes Yes No No Yes No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at Skyline.main(Skyline.java:20)

Test 21

Verdict:

input
10 20
6 8 9 7 9 6 9 5 7 7 
39 44 30 90 6 97 28 39 48 80 8...

correct output
Yes Yes Yes No Yes No Yes Yes ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 22

Verdict:

input
10 20
10 8 10 1 2 4 10 2 3 1 
40 19 39 35 67 40 94 54 85 42 ...

correct output
Yes Yes Yes Yes No Yes No No N...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 23

Verdict:

input
10 20
2 1 10 6 10 5 5 5 4 4 
16 21 70 62 12 30 49 27 64 63 ...

correct output
Yes Yes No No Yes Yes Yes Yes ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 24

Verdict:

input
10 20
1 8 9 3 2 6 6 9 5 9 
2 13 5 21 25 6 10 45 70 3 15 4...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 25

Verdict:

input
10 20
10 6 2 10 9 8 7 7 6 3 
15 98 23 1 70 26 91 44 64 78 1...

correct output
Yes No Yes No No Yes No Yes No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 26

Verdict:

input
10 20
2 10 10 4 4 10 10 6 2 8 
40 77 36 52 49 30 100 19 81 9 ...

correct output
Yes No Yes Yes No Yes No No No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 27

Verdict:

input
10 20
10 4 3 9 1 1 4 2 10 6 
10 53 61 42 54 34 49 63 83 44 ...

correct output
Yes No No Yes No Yes Yes No No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 28

Verdict:

input
10 20
4 8 4 6 10 8 6 10 4 6 
27 51 9 8 42 27 2 50 53 68 87 ...

correct output
No No No Yes Yes No No Yes No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 29

Verdict:

input
10 20
1 10 3 9 4 6 9 3 5 1 
62 44 77 41 41 53 88 48 93 56 ...

correct output
No Yes No Yes Yes No No Yes No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 30

Verdict:

input
10 20
4 6 6 6 2 2 4 2 2 4 
88 42 14 25 14 9 40 35 50 17 3...

correct output
No No Yes No Yes No No No No N...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10
	at Skyline.main(Skyline.java:20)

Test 31

Verdict:

input
100 1000
59286 71521 84428 60278 85796 ...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 32

Verdict:

input
100 1000
99721 72034 93258 12 12813 302...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 33

Verdict:

input
100 1000
18509 2593 93156 54968 94775 4...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 34

Verdict:

input
100 1000
7073 70816 83997 29091 12134 5...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 35

Verdict:

input
100 1000
90064 54725 17270 97270 85564 ...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 36

Verdict:

input
100 1000
5520 87074 83134 20672 36374 9...

correct output
No No Yes No No Yes Yes No Yes...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 37

Verdict:

input
100 1000
94750 33199 20941 82125 6426 4...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 38

Verdict:

input
100 1000
22734 77994 31898 43842 97824 ...

correct output
No Yes No No No Yes No Yes No ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 39

Verdict:

input
100 1000
1112 96856 23945 86921 37753 5...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 40

Verdict:

input
100 1000
36448 50188 49914 49578 756 13...

correct output
Yes Yes No Yes No Yes Yes Yes ...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 100 out of bounds for length 100
	at Skyline.main(Skyline.java:20)

Test 41

Verdict:

input
200 1000
59286 71521 84428 60278 85796 ...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 42

Verdict:

input
200 1000
99721 72034 93258 12 12813 302...

correct output
Yes Yes No Yes Yes Yes Yes Yes...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 43

Verdict:

input
200 1000
18509 2593 93156 54968 94775 4...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 44

Verdict:

input
200 1000
7073 70816 83997 29091 12134 5...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 45

Verdict:

input
200 1000
90064 54725 17270 97270 85564 ...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 46

Verdict:

input
200 1000
5520 87074 83134 20672 36374 9...

correct output
No No No No No No No No Yes No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 47

Verdict:

input
200 1000
94750 33199 20941 82125 6426 4...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 48

Verdict:

input
200 1000
22734 77994 31898 43842 97824 ...

correct output
No Yes No No Yes Yes Yes Yes Y...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 49

Verdict:

input
200 1000
1112 96856 23945 86921 37753 5...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 50

Verdict:

input
200 1000
36448 50188 49914 49578 756 13...

correct output
Yes Yes No Yes No No No Yes No...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 200 out of bounds for length 200
	at Skyline.main(Skyline.java:20)

Test 51

Verdict:

input
2000 100000
59286 71521 84428 60278 85796 ...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2000 out of bounds for length 2000
	at Skyline.main(Skyline.java:20)

Test 52

Verdict:

input
2000 100000
99721 72034 93258 12 12813 302...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2000 out of bounds for length 2000
	at Skyline.main(Skyline.java:20)

Test 53

Verdict:

input
2000 100000
18509 2593 93156 54968 94775 4...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2000 out of bounds for length 2000
	at Skyline.main(Skyline.java:20)

Test 54

Verdict:

input
2000 100000
7073 70816 83997 29091 12134 5...

correct output
Yes Yes Yes Yes Yes Yes Yes Ye...

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2000 out of bounds for length 2000
	at Skyline.main(Skyline.java:20)