939C. Convenient for everybody (sliding window)

Source: Internet
Author: User
Tags time zones local time time interval timezones

In distant to Earth day lasts for n hours and that's why there is N timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n Hours" is Used. When local time in the 1-st timezone are 1 hour, local time in the i-th timezone is I hours.

Some Online programming contests platform wants to conduct a contest the lasts for an hour in such a-to-it Beginni Ng coincides with beginning of some hour (in all time zones). The platform knows, that there is AI people from i-th timezone who want to participate in the contest. Each person would participate if and only if the contest starts no earlier than S hours xx minutes local time and ends not Later than F hours xx minutes local time. Values s and f is equal for all time zones. If the contest starts at f hours xx minutes local time, the person won ' t participate in it.

Help platform Select such a hour, that's the number of people who'll participate in the contest is maximum. Input

The first line contains a single integer n (2≤n≤100)-the number of hours in day.

The second line contains n space-separated integers a1, A2, ..., an (1≤ai≤10), where AI was the number of people in The i-th timezone who want to participate in the contest.

The third line contains the space-separated integers s and f (1≤s < f≤n). Output

Output a single integer-the time of the beginning of the contest (in the first timezone local time), such that the Numbe R of participants'll be maximum possible. If There is many answers, output the smallest among them. Examples Input Copy

1 2 3
1 3
Input Copy
1 2 3 4 1
1 3

In the first example, it's optimal to start competition on 3 hours (in first timezone). In this case, it'll be 1 hour in the second timezone and 2 hours in the third timezone. Only one is from the first timezone won ' t participate.

In second example only people from the third and the fourth timezones would participate.

Daniel's comments written too good, really ashamed of himself ~ ~ ~ ~

Transmission Door

The day of a planet is divided into n hours, so the world of the planet is divided into N time zones, marked as 1~n.

The local time for a time zone is represented as 1~n. The local time interval for the adjacent two time zones is 1 hours. When the "local time" of the 1 time zone is 1 o'clock, the "local time" for the I time zone is I.

An online event is now held for 1 hours. In I time zone, there will be AI participants. If the event starts after "local time" and ends before "local time", then the person in that time zone will participate or not participate. In order to make the world's largest number of participants, the earliest time to start the event (represented as "local time" in 1 time zones).

In this issue, you need to define a "standard Time" and then convert all the "local time" to "Standard Time".

A virtual 0 time zone can be assumed to define the time zone as "Standard Time". Thus: When the "local time" (i.e. "standard Time") of the 0 time zone is 0 o'clock, the "local time" of the I time zone is I.

The "Standard Time" for an event starts with X, so: If I am in the time zone, then:



As a result, the competition was only for [S-x. F-X-1]. Simply enumerate x and sum the number of participants in the corresponding interval to find the maximum number of participants. You can consider the prefix and, or slide the window (note: The sliding direction of the window should be looping to the left). The reference program is as follows:

#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int arr[n];
int main () {
	int n;
	scanf ("%d", &n);
	for (int i=1;i<=n;i++)
	   scanf ("%d", &arr[i%n]);
	int s,f;
	scanf ("%d%d", &s,&f);
	int cur=0;
	for (int i=s;i<=f;i++)
	int maxt=0,index=-1;
	for (int i=0;i<n;i++) {
		int l= (s-i+n)%n;
		int r= (f-i+n)%n;
		if (cur>maxt) {
	printf ("%d\n", index+1);
	return 0;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.