1 / 5
Aug 2023

//for jasnah
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
if (T > 3 || T <= 0) {
return;
}

        while (T-- > 0) {
            int N = scanner.nextInt();

            if (N > 300000 || N <= 0) {
                return;
            }

            long[] heights = new long[N];
            long max_height = 0;
            long count_max_height = 0;

            for (int i = 0; i < N; i++) {
                long m = scanner.nextLong();
                if (m < 0 || m > 1000000) {
                    return;
                }
                heights[i] = m;
                max_height = Math.max(max_height, heights[i]);
            }

            for (int i = 0; i < N; i++) {
                if (heights[i] == max_height) {
                    count_max_height++;
                }
            }

            if (count_max_height % 2 == 1 && max_height != 0) {
                System.out.println(count_max_height);
            } else {
                System.out.println(0);
            }
        }
    }
}

But every time I fail the last test no matter what I do.

  • created

    Aug '23
  • last reply

    Aug '23
  • 4

    replies

  • 333

    views

  • 2

    users

  • 1

    like

  • 1

    link

An additional test case, input:

1
3
4 3 3

Output:

3

Why is the answer 3 if the tallest skyscraper is only one and it’s a “4”?

Goran can win by moving from 4 3 3 to 2 3 3, 1 3 3, or 0 3 3.

My God I still do not understand.The condition says that for each new move the player chooses the tallest skyscraper i.e. in the example with skyscrapers 4 3 3 after Goran’s move when he removes 2 bricks from 4 gets 2 3 3 3.Now Stepan is looking for a new tallest skyscraper ?

Suggested Topics

Want to read more? Browse other topics in Online Judge System or view latest topics.