A. Best Subsegment

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given array a1,a2,…,ana1,a2,…,an. Find the subsegment al,al+1,…,aral,al+1,…,ar (1≤l≤r≤n1≤l≤r≤n) with maximum arithmetic mean 1r−l+1∑i=lrai1r−l+1∑i=lrai(in floating-point numbers, i.e. without any rounding).

If there are many such subsegments find the longest one.

Input

The first line contains single integer nn (1≤n≤1051≤n≤105) — length of the array aa.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) — the array aa.

Output

Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.

Example
input

Copy
5
6 1 6 6 0
output

Copy
2

The subsegment [3,4][3,4] is the longest among all subsegments with maximum arithmetic mean.

题解:题目意思就是让你找一个序列的子序列平均值最大的(如果均值相同,则找最长的)

这题是水题,其实就是找到最大的那个数Maxnum,然后统计Maxnum连续出现的最多次数;

参考代码:

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
int n,a[maxn];
int main()
{
scanf("%d",&n);
int Max=-,ans=-,cnt=;
for(int i=;i<=n;++i) scanf("%d",a+i),Max=max(Max,a[i]);
for(int i=;i<=n;++i)
{
if(a[i]==Max) cnt++;
else ans=max(ans,cnt),cnt=;
}
ans=max(ans,cnt);
cout<<ans<<endl; return ;
}

B. Emotes

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The ii-th emote increases the opponent's happiness by aiai units (we all know that emotes in this game are used to make opponents happy).

You have time to use some emotes only mm times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than kk times in a row (otherwise the opponent will think that you're trolling him).

Note that two emotes ii and jj (i≠ji≠j) such that ai=ajai=aj are considered different.

You have to make your opponent as happy as possible. Find the maximum possible opponent's happiness.

Input

The first line of the input contains three integers n,mn,m and kk (2≤n≤2⋅1052≤n≤2⋅105, 1≤k≤m≤2⋅1091≤k≤m≤2⋅109) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is value of the happiness of the ii-th emote.

Output

Print one integer — the maximum opponent's happiness if you use emotes in a way satisfying the problem statement.

Examples
input

Copy
6 9 2
1 3 3 7 4 2
output

Copy
54
input

Copy
3 1000000000 1
1000000000 987654321 1000000000
output

Copy
1000000000000000000

In the first example you may use emotes in the following sequence: 4,4,5,4,4,5,4,4,54,4,5,4,4,5,4,4,5.

题解:

意思就是给你n个数,然后现在要从这n个数里面挑选m个,每个数可以多次挑选,但不能连续挑选超过k次,(不同位置的数大小相同也是不同的数)

这题就是找到最大和次大的那个数和最大的数出现的次数,然后判断  k==1? 等于一的话,就是最大的数*m, 不等同于1的话,如果最大的数出现的次数

大于1的话,答案也是最大的数*m,如果等于1的话,答案就是k个最大的数,1个次大的数,交替,就是ans=(m-m/(k+1))*Max1+m/(k+1)*Max2;

参考代码:
 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,val,ans;
int main()
{
cin>>n>>m>>k;
ll Max1=,Max2=,cnt=;
for(int i=;i<=n;++i)
{
cin>>val;
if(val>Max1) Max2=Max1,Max1=val,cnt=;
else if(val>Max2) Max2=val;
else if(val==Max1) cnt++;
}
if(k==)
{
if(cnt==) ans=(m-m/)*Max1+(m/)*Max2;
else if(cnt>) ans=m*Max1;
}
else
{
if(cnt>) ans=m*Max1;
else if(cnt==) ans=m/(k+)*Max2+(m-m/(k+))*Max1;
}
cout<<ans<<endl;
///////////////////////////////////
return ;
}

C. Magic Ship

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You a captain of a ship. Initially you are standing in a point (x1,y1)(x1,y1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (x2,y2)(x2,y2).

You know the weather forecast — the string ss of length nn, consisting only of letters U, D, L and R. The letter corresponds to a direction of wind. Moreover, the forecast is periodic, e.g. the first day wind blows to the side s1s1, the second day — s2s2, the nn-th day — snsn and (n+1)(n+1)-th day — s1s1 again and so on.

Ship coordinates change the following way:

  • if wind blows the direction U, then the ship moves from (x,y)(x,y) to (x,y+1)(x,y+1);
  • if wind blows the direction D, then the ship moves from (x,y)(x,y) to (x,y−1)(x,y−1);
  • if wind blows the direction L, then the ship moves from (x,y)(x,y) to (x−1,y)(x−1,y);
  • if wind blows the direction R, then the ship moves from (x,y)(x,y) to (x+1,y)(x+1,y).

The ship can also either go one of the four directions or stay in place each day. If it goes then it's exactly 1 unit of distance. Transpositions of the ship and the wind add up. If the ship stays in place, then only the direction of wind counts. For example, if wind blows the direction Uand the ship moves the direction L, then from point (x,y)(x,y) it will move to the point (x−1,y+1)(x−1,y+1), and if it goes the direction U, then it will move to the point (x,y+2)(x,y+2).

You task is to determine the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2).

Input

The first line contains two integers x1,y1x1,y1 (0≤x1,y1≤1090≤x1,y1≤109) — the initial coordinates of the ship.

The second line contains two integers x2,y2x2,y2 (0≤x2,y2≤1090≤x2,y2≤109) — the coordinates of the destination point.

It is guaranteed that the initial coordinates and destination point coordinates are different.

The third line contains a single integer nn (1≤n≤1051≤n≤105) — the length of the string ss.

The fourth line contains the string ss itself, consisting only of letters U, D, L and R.

Output

The only line should contain the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2).

If it's impossible then print "-1".

Examples
input

Copy
0 0
4 6
3
UUU
output

Copy
5
input

Copy
0 3
0 0
3
UDD
output

Copy
3
input

Copy
0 0
0 1
1
L
output

Copy
-1
题解:
  题目意思就是一艘船要从起点(x1,y1)到达终点(x2,y2),每天的风向是不同的,给出了n天的风向信息(每n天具有周期性),且每天小船可以往一个方向移动一个单位或者不移动; 让你求到达终点的最短时间,如果不能到达就返回-; 这题由于答案具有单调性,因此可以二分答案m;对于风的速度和船的速度可以分开计算; 我们先计算出在m天风可以使小船移动到的位置,然后其和终点(x2,y2)的曼哈顿距离如果大于天数,则不能,小于等于天数则满足。一直二分答案,求出最小的天数;
参考代码:
 #include<bits/stdc++.h>
#define maxl 100010
using namespace std;
typedef long long ll;
#define clr(a,val) memset(a,val,sizeof(a))
#define fi first
#define se second
#define pb push_back
const int INF=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
int n;
int a[maxl];
ll sx,sy,ex,ey,cx=,cy=;
ll tx[maxl],ty[maxl],sumx[maxl],sumy[maxl];
char ch[maxl];
ll ans;
bool judge(ll mid)
{
ll fx=mid/n*sumx[n]+sumx[mid%n];
ll fy=mid/n*sumy[n]+sumy[mid%n];
if(abs(ex-(sx+fx))+abs(ey-(sy+fy))<=mid) return ;
else return ;
}
void solve()
{
ll resx=ex-sx,resy=ey-sy,d=,res=abs(resx)+abs(resy);
for(int i=;i<=n;i++)
{
if(tx[i]*resx>) res--;
else res++;
if(ty[i]*resy>) res--;
else res++;
if(res<=i){ans=i;return;}
}
if(resx*cx<= && cx!=) d+=cx;
if(resy*cy<= && cy!=) d+=cy;
if(d>=n){ans=-;return;}
ll l=,r=1ll<<,mid;
while(l+<r)
{
mid=(l+r)>>;
if(judge(mid)) r=mid;
else l=mid;
}
if(judge(l)) ans=l;
else if(judge(r)) ans=r;
else ans=-;
}
int main()
{
sx=read();sy=read();ex=read();ey=read();
scanf("%d",&n);
scanf("%s",ch+);
for(int i=;i<=n;i++)
{
if(ch[i]=='U') tx[i]=,ty[i]=;
if(ch[i]=='D') tx[i]=,ty[i]=-;
if(ch[i]=='L') tx[i]=-,ty[i]=;
if(ch[i]=='R') tx[i]=,ty[i]=;
sumx[i]=sumx[i-]+tx[i];
sumy[i]=sumy[i-]+ty[i];
cx+=tx[i];cy+=ty[i];
}
solve();
cout<<ans<<endl;
return ;
}

CoderForces Round60-(1117A,1117B,1117C题解)的更多相关文章

  1. CoderForces Round526 (A~E)题解

    A. The Fair Nut and Elevator time limit per test 1 second memory limit per test 256 megabytes input ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

随机推荐

  1. Jmeter与压测相关概念

    相关概念 RT(response time) 什么是RT? RT就是指系统在接收到请求和做出相应这段时间跨度 但是值得一提的是RT的值越高,并不真的就能说明我们的系统的吞吐量就很高, 比如说,如果存在 ...

  2. HTML——基础知识点1

  3. Servlet相关学习

    Servlet入门解析 概念 运行在服务器端的小程序 servlet就是一个接口,定义了Java类被浏览器访问到(tomcat识别)的规则 实现servlet接口.复写方法 快速入门 创建web项目 ...

  4. JVM 运行参数 & 代码监控

    1.Java代码监控 JDK提供java.lang.management包, 其实就是基于JMX技术规范,提供一套完整的MBean,动态获取JVM的运行时数据,达到监控JVM性能的目的. packag ...

  5. Salesforce学习之路(十)Org的命名空间

    1. 命名空间的适用场景 每个组件都是命名空间的一部分,如果Org中设置了命名空间前缀,那么需使用该命名空间访问组件.否则,使用默认命名空间访问组件,系统默认的命名空间为“c”. 如果Org没有创建命 ...

  6. nyoj 82-迷宫寻宝(一) (多重BFS)

    82-迷宫寻宝(一) 内存限制:64MB 时间限制:1000ms 特判: No 通过数:3 提交数:5 难度:4 题目描述: 一个叫ACM的寻宝者找到了一个藏宝图,它根据藏宝图找到了一个迷宫,这是一个 ...

  7. 领扣(LeetCode)最大连续1的个数 个人题解

    给定一个二进制数组, 计算其中最大连续1的个数. 示例 1: 输入: [1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3. 注意: 输入的数组 ...

  8. android逆向总结

    首先项目里的java文件,以及项目引用到的第三方jar或aar包里面的class,统统都编译成classes.dex放在apk包的根目录,项目的资源目录和AndroidManifest.xml被处理生 ...

  9. iOS UIView x Android View

  10. CentOS7中安装MariaDB

    什么是mariaDB? 在线安装(慢的要命) RPM离线安装(CentOS7.X) 在线安装 打开官方网站 https://mariadb.org/ 点击Download,跳转到下一页面 继续点击Do ...