cf 468 C. Convenient For Everybody

噁心........ 知道怎麼做就是時間沒算出來,你說尷不尷尬

從國外友人哪裏學到 時間打法 循環餘 改變時間 看代碼簡單易懂版本

C. Convenient For Everybody
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In distant future on Earth day lasts for n hours and that's why there are 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 is 1 hour, local time in the i-th timezone is i hours.

Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.

Help platform select such an hour, that the number of people who will participate in the contest is maximum.

Input

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

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

The third line contains two 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 number of participants will be maximum possible. If there are many answers, output the smallest among them.

Examples
Input
Copy
3
1 2 3
1 3
Output
3
Input
Copy
5
1 2 3 4 1
1 3
Output
4
Note

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

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


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define INF 0x7f
const int maxn =1e5+6; 
typedef long long ll ;
#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)
 
ll a[2*maxn],sum[maxn<<1]; 
int n;
ll calc( int l , int r)
{
	l++,r++;

	if(l<=r)return sum[r]-sum[l-1];
	else return sum[n]-sum[l-1]+sum[r];
}
int main()
{
	
	 cin>>n;
	 f(i,1,n)
	{
		 cin>>a[i];
		 a[i+n]=a[i];
	 }
	 f(i,1,n)
	 {
		 sum[i]=sum[i-1]+a[i];
	 } 
	int s,f, cnt=0;
	cin>>s>>f;
    s--;
	f--;
	f--;
	ll ans = -2147483647 ;
 
	f(i,1,n)
	{
		ll tot = calc(s,f);
		if(tot>ans)
			ans=tot,cnt=i;
		f=(f-1+n)%n;
		s=(s-1+n)%n;
	} 
	cout<<cnt<<endl;
	 
 
	return 0;

}







未來的我一定會感謝現在正在成長的我

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章