Hora

시간 제한1초메모리 제한2048 MB

요약
원형 구간에 있는 남학생 수를 묻는 질의를 이용해, 남학생과 여학생 수의 차이가 가장 작은 길이 K의 원형 구간을 찾는다.
난이도

보통10점 중 7점

유형
이분 탐색, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

This is an interactive problem!

Hora is a traditional Romanian and Moldovan folk dance in which participants join hands and form a large circle...

At the 8th European Junior Olympiad in Informatics, NN participants started dancing hora, where NN is a positive, even integer. The number of boys is equal to the number of girls. The organizers assigned a circular index to every participant in the hora. The indexes start from 00 and continue consecutively in increments of 11, up to N−1N - 1. This means that participants with indexes 00 and N−1N - 1 are neighbors, and that each participant’s index is one greater than that of their previous neighbor. Please refer to the Examples section for visualizing such a configuration.

You don't know exactly which participants are girls and which participants are boys, since you are participating in the competition right now! However, you can make calls to the testing system. Each call consists of two integers LL and RR such that 0≤L<N0 ≤ L < N and 0≤R<N0 ≤ R < N. The response will contain an integer - the number of boys on the continuous circular interval from LL to RR in our circle. In particular:

  • If L≤RL ≤ R, then the answer will consider the continuous circular interval of participants with indexes L,L+1,…,R−1,RL,L + 1, \dots ,R - 1,R.
  • If R<LR < L, then the answer will consider the continuous circular interval of participants with indexes L,L+1…N−1,0,…,R−1,RL,L + 1…N - 1, 0, \dots , R - 1,R.

You are given an integer KK (1≤K≤N1 ≤ K ≤ N). Your task is to find a continuous circular interval of length KK in our circle for which the absolute difference between the number of boys and girls is as small as possible. More formally, you are asked to implement a procedure that returns an integer SS (0≤S<N0 ≤ S < N) such that a continuous circular interval of length KK starting from SS has the smallest absolute difference between the number of boys and the number of girls among all the possible continuous circular intervals of length KK. Note that a certain circle configuration may have multiple solutions with the same smallest absolute difference between the number of boys and girls. In such a case, you may return any of them.

The absolute difference between two numbers xx and yy is given by ∣x−y∣|x - y|. For example, ∣2−4∣=2|2 - 4| = 2, ∣7−4∣=3|7 - 4| = 3.

제한

  • 2≤N≤1052 ≤ N ≤ 10^5
  • 1≤K≤N1 ≤ K ≤ N
  • NN is even.
  • The hora has an equal number of participating boys and girls.
  • The grader is not adaptive.

예제

이 문제는 공개된 예제가 없습니다.