oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

ballot Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

ballot.html

Problem Description

Ranald the cat is implementing a ballot system to select C students to attend CS3233. However, he doesn't know how to implement it!

So, if you code it for him, you should stand a higher chance in going to attend CS3233.

Ballot System Description

Each student gets to choose his/her unique ballot number from 1 to 1000000000. Furthermore, there will be N students labelled from 1 to N.

In order to select a student, Ranald chooses a number from 1 to 1000000000 as well. The student whose ballot number is the closest to the number Ranald selects will get to go for CS3233! In the event that 2 students are concurrently closest to the number selected, the student with a lower ballot number will get to go! Once a student is selected, his ballot ticket will be removed from the ballot system.

Limits

Subtask 1 (20%): 0 < C ≤ N ≤ 100.

Subtask 2 (30%): 0 < C ≤ N ≤ 1000.

Subtask 3 (50%): 0 < C ≤ N ≤ 100000.

Input

The first line of input consists of 2 integers, N followed by C.

The following line will consist of N integers, which are the ballot number of the students. The ith number in this line is the ballot number of the ith student (student with label i).

The following line will consist of C integers, which are the numbers that Ranald picks. These numbers are provided in chronological order, where the first number is selected first.

Output

Output C lines with 1 integer each. These C integers should denote which students will get to attend CS3233 (print their student labels) in any order.

Sample Input 1

5 3
10 13 14 9 15
12 12 12

Sample Output 1

2
1
3

Explanation for Sample Output 1

When Ranald chose the number '12', the ballot number of '13' is the closest to 12. Therefore, the corresponding student '2' gets selected for CS3233.

When Ranald chose the number '12' again, number '10' and '14' are of equal distance to 12. Therefore, the student with the lower ballot number ('10') will get to go for CS3233. (This is student '1').

When Ranald chose the number '12' yet again, '14' is the closest to 12. Therefore, the corresponding student '3' gets selected for CS3233. This is because the ballot numbers of '10' and '13' have already been removed from the system.

Sample Input 2

5 3
10 13 14 9 15
12 12 12

Sample Output 2

1
2
3

Explanation for Sample Output 2

Same as above, but in a different order of output.

Tags

Data Structure, CS3233 2013 Selection Test

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
120101s64MBMinimum
230201s64MBMinimum
350201s64MBMinimum
4021s64MBMinimum

Judge Compile Command

g++-8 ans.cpp -o ballot -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.