Codeforces Round #464 (Div. 2) C. Convenient For Everybody
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.
解题心得:
- 有n个时区,每个时区有一定的人数,给你一个区间[l,r),要你选择一段连续的时区,长度为所给的区间长度,要求时区里面人数总和最多并且这个时区以l为当前的时间,输出第一个时区此时的时间。
- 题目很绕,看了老半天,其实还是很简单的,首先要明白时间是循环的,先枚举得出每一段区间(长度为所给的区间长度)的人数总和,然后选出最大的那一段区间,逆推第一个时区的时间。
#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的更多相关文章
- Codeforces Round #464 (Div. 2) E. Maximize!
题目链接:http://codeforces.com/contest/939/problem/E E. Maximize! time limit per test3 seconds memory li ...
- Codeforces Round #464 (Div. 2)
A. Love Triangle time limit per test: 1 second memory limit per test: 256 megabytes input: standard ...
- Codeforces Round #464 (Div. 2) D. Love Rescue
D. Love Rescue time limit per test2 seconds memory limit per test256 megabytes Problem Description V ...
- Codeforces Round #464 (Div. 2) B. Hamster Farm
B. Hamster Farm time limit per test2 seconds memory limit per test256 megabytes Problem Description ...
- Codeforces Round #464 (Div. 2) A Determined Cleanup
A. Love Triangle time limit per test1 second memory limit per test256 megabytes Problem Description ...
- 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 ...
- 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 ...
- Codeforces Round #464 (Div. 2) D题【最小生成树】
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her b ...
- 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 ...
随机推荐
- java中key值可以重复的map:IdentityHashMap
在Java中,有一种key值可以重复的map,就是IdentityHashMap.在IdentityHashMap中,判断两个键值k1和 k2相等的条件是 k1 == k2 .在正常的Map 实现(如 ...
- Unity C# 调用SaveFileDialog保存Excel文件
本文原创,转载请注明出处:http://www.cnblogs.com/AdvancePikachu/p/6893934.html 本文学习如何把数据转存为Excel文件并调用SaveFileDial ...
- 发布MVC网站的时候出现缺少WebHost等程序集问题的解决办法
将一下几个dll 拷贝到bin文件夹下就行 链接:https://pan.baidu.com/s/17xhTdakzM_SQmOjJdZvviw 密码:c976
- (2017.9.27) 自定义列表项 list-style 使用心得
今天给某公司做招聘专页.早上完成设计图,下午开始排版.页面套用了我之前做的某人才局的招聘页面,导航栏.banner 很快就出来了.这次内容里我有些地方用了列表,当然要用 <ul> < ...
- IOS微信6.7.4输入框失去焦点,软键盘关闭后,被撑起的页面无法回退到原来正常的位置
近期在开发微信H5页面时碰到这个问题,如图,软键盘弹起后,若原输入框被遮挡,页面整体将会上移,然而当输入框失焦,软键盘收起后,页面未恢复,这也是ios的微信版本更新6.7.4之后才遇到的bug. 目前 ...
- ArcGIS中Features与JSON的互相转化
实际操作过程非常简单,这里就简单记录下转换工具的位置:
- python 之 BeautifulSoup 常用提取
一.bs4信息提取后返回的数据类型 soup.find('tbody') ---> 返回结构是一个bs4.element.Tag soup.find('tbody').children ---& ...
- linux打开进程数测试
查看linux默认打开最大打开进程数 具体参考:https://www.jb51.net/article/143667.htm #include <unistd.h> #include & ...
- 倍增LCA
前言 在做树上问题时,我们经常会遇到 \(LCA\)(最近公共祖先)问题.曾经的我遇到这类问题只会\(O(n)\)暴力求解,学了倍增\(LCA\),就可以\(O(logn)\)解决了. 简介 倍增\( ...
- Matlab 中实用数据结构之 containers.Map
概要 熟悉 Python 的都知道字典 Dict 类型数据结构功能的强大,Matlab 中虽然有表结构,但是其列名必须是亦变量名类型的字符串,如果我想用数字开头的字符串作键值,其表结构就无能为力了 ...