Submission details
Task:Kyselyt
Sender:TapaniS
Submission time:2025-10-19 21:29:05 +0300
Language:Java
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
#40
Test results
testverdicttimegroup
#1ACCEPTED0.16 s1, 2, 3, 4details
#2ACCEPTED0.16 s1, 2, 3, 4details
#3ACCEPTED0.16 s1, 3, 4details
#4--2, 3, 4details
#5--2, 3, 4details
#6--2, 3, 4details
#7--3, 4details
#8--4details
#9--4details
#10--4details
#11--3, 4details
#12--4details
#13--3, 4details
#14--4details
#15--4details
#16--4details

Code

import java.util.*;

public class kyselyt {


	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		String kokomaara =  input.nextLine();
		
		String[] kokomaaraParts = kokomaara.split("\\s+");
		
		int n = Integer.parseInt(kokomaaraParts[0]);
		int q = Integer.parseInt(kokomaaraParts[1]);
		
		// int t = Integer.parseInt(input.nextLine());
		
		int[] x = new int[n];  // luvut
		int[] a = new int[q];  // alku
		int[] b = new int[q];  // loppu
		
		String num =  input.nextLine();
		String[] numParts = num.split("\\s+");
		
		for (int i = 0; i < n; i++) {
			x[i] = Integer.parseInt(numParts[i]);
		}

		String[] rajat = new String[q]; // numerot

		for (int i = 0; i < q; i++) {
			
			rajat[i] =  input.nextLine();
			
			String[] rajaParts = rajat[i].split("\\s+");
			a[i] = Integer.parseInt(rajaParts[0]);
			b[i] = Integer.parseInt(rajaParts[1]);
		}

		input.close(); 
		
		// Program here

		StringBuilder sb = new StringBuilder();


		for (int i = 0; i < q; i++) {	 // tapaus q
		
			int ans = -1;
			int pit = b[i] - a[i] + 1;
			float suhde = 0.0f;

			int[] counts = new int[101];
			
			
			// Map<Integer, Integer> counts = new HashMap<>();

			for (int i2 = (a[i]-1); i2 <= (b[i]-1); i2++) {
				// counts.put(x[i2], counts.getOrDefault(x[i2], 0) + 1);
				counts[x[i2]]++;
			}

			int mostCommon = 0;
			int highestCount = 0;

		/*
			for (Map.Entry<Integer, Integer> entry : counts.entrySet()) {
				if (entry.getValue() > highestCount) {
					highestCount = entry.getValue();
					mostCommon = entry.getKey();
				}
			}
		*/
		
        for (int i3 = 1; i3 <= 100; i3++) {
            if (counts[i3] > highestCount) {
                highestCount = counts[i3];
                mostCommon = i3;
            }
        }

			suhde = (float)highestCount / pit;
			
			if (suhde > 0.5) {
				ans = mostCommon;
			}

			sb.append(ans).append('\n');

		}   // tapaus q



		// tulostus
		
		// System.out.println(dy + " " + dx);		

		System.out.print(sb.toString());

    }
}

Test details

Test 1

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 2

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
100 100
2 1 2 2 1 2 2 2 1 2 2 1 1 1 1 ...

correct output
2
1
1
2
1
...

user output
2
1
1
2
1
...

Test 3

Group: 1, 3, 4

Verdict: ACCEPTED

input
100 100
5 19 44 88 14 79 50 44 14 99 7...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 4

Group: 2, 3, 4

Verdict:

input
100000 100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
1
1
1
1
...

user output
(empty)

Test 5

Group: 2, 3, 4

Verdict:

input
100000 100000
1 1 1 2 1 2 1 1 2 1 1 1 1 2 2 ...

correct output
1
1
2
1
1
...

user output
(empty)

Test 6

Group: 2, 3, 4

Verdict:

input
100000 100000
8 2 6 1 10 4 9 7 8 10 4 2 8 2 ...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 7

Group: 3, 4

Verdict:

input
100000 100000
141307 493258596 365539511 222...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 8

Group: 4

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
1
1
1
1
...

user output
(empty)

Test 9

Group: 4

Verdict:

input
200000 200000
1 2 2 2 1 2 2 1 1 1 1 1 1 1 1 ...

correct output
2
2
2
2
2
...

user output
(empty)

Test 10

Group: 4

Verdict:

input
200000 200000
286470749 280175209 741317063 ...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 11

Group: 3, 4

Verdict:

input
100000 100000
613084013 1000000000 411999902...

correct output
-1
-1
-1
-1
1000000000
...

user output
(empty)

Test 12

Group: 4

Verdict:

input
200000 200000
613084013 1000000000 411999902...

correct output
1000000000
1000000000
-1
1000000000
-1
...

user output
(empty)

Test 13

Group: 3, 4

Verdict:

input
100000 100000
663307073 663307073 663307073 ...

correct output
329574367
965067805
768744535
691214891
21873594
...

user output
(empty)

Test 14

Group: 4

Verdict:

input
200000 200000
663307073 663307073 663307073 ...

correct output
107596959
249558965
679275202
760593154
725418770
...

user output
(empty)

Test 15

Group: 4

Verdict:

input
200000 200000
663307073 663307073 663307073 ...

correct output
211070558
49212342
651109313
264549124
651109313
...

user output
(empty)

Test 16

Group: 4

Verdict:

input
200000 200000
2 2 2 1 2 1 1 2 2 1 1 1 1 2 1 ...

correct output
1
2
1
1
1
...

user output
(empty)