2018-03-03

http://codeforces.com/problemset/problem/939/C

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.

题意:在未来,一天一共有n个小时,也一共有n个时区,每两个相邻的时区之间差是一个小时。现在有一些网站想要举办在线编程比赛,希望有最多的人能参与。因为人们以自己的时区的时间为标准,只参加在s点以后(包括s点)开始的且在f点之前(包括f点)的比赛。每场比赛的时间为1个小时,让你求出比赛在什么时间开始会有最多的人参加,输出以第一个时区的时间为标准的开始时间。

感想:错了好几次,主要问题在 数据类型不对导致的RE、TLE以及一个坑点:没考虑到可以是后面的时区可以比开头的时区要早一点开始比赛。其他还有一些问题在cf提交的地方看。关于TLE的反思,以后做题先计算复杂度再做题,不要想当然。有一些循环是可以变化为等式降低复杂度的,就不用写得跟之前一样麻烦了...

Code

#include<string.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define MAX 0x3f3f3f3f
#define fi first
#define se second
#define LL long long
int a[];
int main()
{
int n,s,f;
int ans;
/*int ans,p1,p2,p3,p4;*/
while(cin>>n)
{
for(int i=;i<=n;i++)
cin>>a[i]; cin>>s>>f;
int t=f-s;
LL maxn=; //
for(int i=;i<=t;i++)
maxn+=a[i];
/*int flag=1;*/
LL cc=maxn; //
/*p2=s*/;
ans=s; //这个地方又是一个坑点,错在样例28
for(int i=;i<=n-t+;i++)
{
cc=cc-a[i-]+a[i+t-];
if(cc>maxn)
{ maxn=cc;
/*flag=i;
p1=(flag-1)%n;
p2=s;
while(p1--)
{
if(p2==1)
p2=n;
else
p2--;
}
ans=p2;*/
ans=s-i+;
if(ans<=)
ans+=n;
}
else if(cc==maxn)
{ /*p3=(i-1)%n;
p4=s;
while(p3--)
{
if(p4==1)
p4=n;
else
p4--;
}
if(p4<p2)
{ans=p4;p2=p4;}*/
int tmp=s-i+;
if(tmp<=) tmp+=n; //其实修正的时候 加n减n结合前面的等式是等价的
ans=min(ans,tmp); }
}
int q=;
for(int i=n+;i<=n+t-;i++)
{
a[i]=a[q++];
}
for(int i=n-t+;i<=n+t-;i++)
{
cc=cc-a[i-]+a[i+t-];
if(cc>maxn)
{
maxn=cc;
/* flag=i;
p1=(n+1)-flag;
p2=s;
while(p1--)
{
if(p2==n)
p2=1;
else
p2++;
}
ans=p2;*/
ans=s+n-i+;
if(ans>n)
ans-=n; }
else if(cc==maxn)
{
/*flag=i;
p3=n+1-flag;
p4=s;
while(p3--)
{
if(p4==n)
p4=1;
else
p4++;
}
if(p4<p2)
{ans=p4;p4=p2;} */
int tmp=s+n-i+;
if(tmp>n) tmp-=n;
if(tmp<ans) ans=tmp;
} }
cout<<ans<<endl;
}
}

其他人的写法

http://blog.csdn.net/ssimple_y/article/details/79333325

http://blog.csdn.net/islittlehappy/article/details/79336482

Codeforces 939C - Convenient For Everybody的更多相关文章

  1. Spring Boot Reference Guide

    Spring Boot Reference Guide Authors Phillip Webb, Dave Syer, Josh Long, Stéphane Nicoll, Rob Winch,  ...

  2. Codeforces Round #464 (Div. 2) C. Convenient For Everybody

    C. Convenient For Everybody time limit per test2 seconds memory limit per test256 megabytes Problem ...

  3. Codeforces Beta Round #2 A,B,C

    A. Winner time limit per test:1 second memory limit per test:64 megabytes input:standard input outpu ...

  4. Login Verification CodeForces - 928A (实现)

    When registering in a social network, users are allowed to create their own convenient login to make ...

  5. Codeforces Round #102 (Div. 1) A. Help Farmer 暴力分解

    A. Help Farmer 题目连接: http://www.codeforces.com/contest/142/problem/A Description Once upon a time in ...

  6. Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game

    地址:http://codeforces.com/contest/811/problem/D 题目: D. Vladik and Favorite Game time limit per test 2 ...

  7. Codeforces Beta Round #2 C. Commentator problem 模拟退火

    C. Commentator problem 题目连接: http://www.codeforces.com/contest/2/problem/C Description The Olympic G ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. python基础类型—字典

    字典 字典是python中唯一的映射类型,采用键值对(key-value)的形式存储数据.python对key进行哈希函数运算,根据计算的结果决定value的存储地址,所以字典是无序存储的,且key必 ...

  2. Content-Length mismatch, received 431737 bytes out of the expected 760836

    可能原因是 composer 的安装包网址是国外镜像所致,被长城防火墙屏蔽了.可执行以下命令来解决:composer config -g repo.packagist composer https:/ ...

  3. mybatis09--自连接一对多查询

    查询导师 下面的所有 老师的信息! 创建实体类 和对应的数据库 /** *导师的实体类 */ public class Teacher { private Integer id; private St ...

  4. laravel5.4将excel表格中的信息导入到数据库中

    本功能是借助 Maatwebsite\Excel 这个扩展包完成的,此扩展包的安装过程请参考上篇博文:http://www.cnblogs.com/zhuchenglin/p/7122946.html ...

  5. Newtonsoft.Json转换强类型DataTable错误:Self referencing loop detected with type ......

    问题,在使用Newtonsoft.Json对强类型的DataTable进行系列化时会出现循环引用错误 解决办法,不要直接系列化强类型的DataTable,改为 JsonConvert.Serializ ...

  6. day14 十四、三元运算符,推导式,匿名内置函数

    一.三元(目)运算符 1.就是if...else...语法糖 前提:if和else只有一条语句 # 原来的做法 cmd = input('cmd:>>>') if cmd.isdig ...

  7. 二叉查找树,AVL树,伸展树【CH4601普通平衡树】

    最近数据结构刚好看到了伸展树,在想这个东西有什么应用,于是顺便学习一下. 二叉查找树(BST),对于树上的任意一个节点,节点的左子树上的关键字都小于这个节点的关键字,节点的右子树上的关键字都大于这个节 ...

  8. vue里面的v-for列表循环

    列表渲染 v-for v-for可以把数据中的一个数组对应为一组元素v-for 指令需要以 item in items 形式的特殊语法, items 是源数据数组并且 item 是数组元素迭代的别名. ...

  9. ssl证书

    个人理解: 客户端第一次连接服务端的时候,服务端就把证书(中的公钥)给了客户端,客户端验证证书中的公钥是否和本地的公钥一致(客户端一般都会内置类似AC的具有公信力的证书颁发机构), 之后的请求每次请求 ...

  10. 多线程Thread

    多线程的意义 使用多线程可以充分利用CPU资源.提高CPU的使用率,采用多线程的方式去同时完成几件事情而不互相干扰.在处理大量的IO操作或处理的情况需要花费大量的时间时(如:读写文件,视频图像的采集, ...