C. Convenient For Everybody

time limit per test2 seconds

memory limit per test256 megabytes

Problem Description

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

3

1 2 3

1 3

output

3

input

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.


解题心得:

  1. 有n个时区,每个时区有一定的人数,给你一个区间[l,r),要你选择一段连续的时区,长度为所给的区间长度,要求时区里面人数总和最多并且这个时区以l为当前的时间,输出第一个时区此时的时间。
  2. 题目很绕,看了老半天,其实还是很简单的,首先要明白时间是循环的,先枚举得出每一段区间(长度为所给的区间长度)的人数总和,然后选出最大的那一段区间,逆推第一个时区的时间。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
int num[maxn],n,l,r,len,sum[maxn],L,Max,ans; void check(){
int cnt = 2;
Max = sum[1];
l = 1,r = len;
while(cnt <= n){
r++;
if(r > n)//时间是循环的
r -= n;
sum[cnt] = sum[cnt-1] - num[l] + num[r];//得到区间和
l++;
if(sum[cnt] > Max)
Max = sum[cnt];
cnt++;
}
} void get_ans(){
ans = 1e18;
for(int i=1;i<=n;i++){
if(sum[i] == Max) {//找到最大的和并且第一个时区的时间最小
int temp = L-i+1;
if(temp <= 0)
temp += n;
if(temp < ans){
ans = temp;
}
}
}
} int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&num[i]);
scanf("%d%d",&l,&r);
L = l;
len = r-l;
for(int i=1;i<=len;i++)
sum[1] += num[i];
check();
get_ans();
printf("%d",ans);
return 0;
}

Codeforces Round #464 (Div. 2) C. Convenient For Everybody的更多相关文章

  1. Codeforces Round #464 (Div. 2) E. Maximize!

    题目链接:http://codeforces.com/contest/939/problem/E E. Maximize! time limit per test3 seconds memory li ...

  2. Codeforces Round #464 (Div. 2)

    A. Love Triangle time limit per test: 1 second memory limit per test: 256 megabytes input: standard ...

  3. Codeforces Round #464 (Div. 2) D. Love Rescue

    D. Love Rescue time limit per test2 seconds memory limit per test256 megabytes Problem Description V ...

  4. Codeforces Round #464 (Div. 2) B. Hamster Farm

    B. Hamster Farm time limit per test2 seconds memory limit per test256 megabytes Problem Description ...

  5. Codeforces Round #464 (Div. 2) A Determined Cleanup

    A. Love Triangle time limit per test1 second memory limit per test256 megabytes Problem Description ...

  6. Codeforces Round #464 (Div. 2) B. Hamster Farm[盒子装仓鼠/余数]

    B. Hamster Farm time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. Codeforces Round #464 (Div. 2) A. Love Triangle[判断是否存在三角恋]

    A. Love Triangle time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. Codeforces Round #464 (Div. 2) D题【最小生成树】

    Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her b ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. SpringBoot | 第十四章:基于Docker的简单部署

    前言 讲解了单元测试,本章节讲讲应用的部署吧.总体而言,在进行自动化部署时,基本都会用上Jenkins+Maven+Docker进行部署.本章节主要讲解使用Maven+Docker进行SpringBo ...

  2. Authentication to host '***‘' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream has failed.

    如下场景: 一个页面中需要用户填入文字信息,并上传图片,上传图片是单独调用上传文件接口的,当用户上传图片后,马上点保存,就会报错. Authentication to host '***‘' for ...

  3. Mavlink 协议 理解

    来源:blog.csdn.net/super_mice/article/details/44836585 之前看了mavlink协议,网上关于mavlink的资料不多.本文大概总结了下对mavlink ...

  4. vue awaresome swiper的使用

    main.jsimport VueAwesomeSwiper from 'vue-awesome-swiper'import 'swiper/dist/css/swiper.css'Vue.use(V ...

  5. js清除缓存以及jsp缓存[部分常用]

    参考: http://bbs.csdn.net/topics/330028896  浏览器缓存机制 http://www.docin.com/p-591569918.html  浏览器缓存的一些问题的 ...

  6. Eucalyptus简介

    1.Eucalyptus是什么? Eucalyptus  n.桉树 Eucalyptus is a Linux-based software architecture that implements ...

  7. Java有关List的stream基本操作

    参考博客: https://www.jianshu.com/p/9fe8632d0bc2 Stream简介 Java 8引入了全新的Stream API.这里的Stream和I/O流不同,它更像具有I ...

  8. HDU 3351 Seinfeld 宋飞正传(水)

    题意: 给出一个串,串内只有大括号,问经过几次改变可使全部括号合法?改变指的是可以将某一方向的括号变成另一方向. 思路: 利用栈的特点,若出现成对的合法括号,直接删掉,留下那些不合法的成为一串.既然不 ...

  9. innobackupex实现对MySQL的增量备份与还原

    备份增量备份是基于完整备份的,所以我们需要先做一次完整备份: innobackupex --defaults-file=/etc/my.cnf --user root --password cheng ...

  10. NOIP2018赛前停课集训记——最后的刷板子计划

    前言 再过两天就\(NOIP2018\)了. 于是,我决定不做其他题目,开始一心一意刷板子了. 这篇博客记录的就是我的刷板子计划. [洛谷3383][模板]线性筛素数 这种普及-的题目我还写挂了两次( ...