当前位置:网站首页>Niuke small Bai monthly race 52 D ring insectivorous (feet +st table)
Niuke small Bai monthly race 52 D ring insectivorous (feet +st table)
2022-06-29 17:56:00 【eva_ can(not)survive】
Sign in — major IT Written interview preparation platform _ Cattle from Niuke.com is the magic weapon of Internet Job Hunting ,C++、Java、 front end 、 product 、 Operational skills learning / Test preparation / Job search question bank , Online Baidu Alibaba Tencent Netease and other Internet famous enterprises written interview simulation test practice , Discuss the classic test questions with Niu Ren , Improve your technical ability in an all-round way
https://ac.nowcoder.com/acm/contest/11229/D Obviously, the title description is a ring , So the array is doubled , Then take the interval through the double pointer ruler , use st The table shows that the range of pretreated cream is the largest , When taking a ruler, you need to pay attention to the boundary ,r-l Need to be less than or equal to n, Otherwise, you will eat air and make the answer wrong .
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lowbit(x) ((x)&(-x))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
const int MAXN=1e6+5;
const int INF=0x3f3f3f3f;
const ll NNF=0x3f3f3f3f3f3f3f3f;
int n;
ll s;
ll a[MAXN];
ll st[MAXN][24];
ll query(int x,int y){
int s=log2(y-x+1);
return max(st[x][s],st[y-(1<<s)+1][s]);
}
void solve(){
scanf("%d %lld",&n,&s);
for(int i=1;i<=n;i++) scanf("%lld",a+i);
for(int i=1;i<=n;i++) scanf("%lld",&st[i][0]);
for(int i=n+1;i<=2*n;i++){
a[i]=a[i-n];
// b[i]=b[i-n];
st[i][0]=st[i-n][0];
}
for(int i=1;i<=23;i++){
for(int j=1;j+(1<<i)-1<=2*n;j++){
st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
}
}
int l,r;
l=r=1;
ll sum=0;
// int mx=0;
ll ans=INF;
while(l<=r){
while(r<=2*n&&sum<s){
// mx=max(mx,a[r]);
sum+=a[r++];
}
while(r-l>n){
sum-=a[l++];
}
if(sum>=s){
ll mx=query(l,r-1);
ans=min(ans,mx);
}else if(r>2*n) break;
if(l<=r){
sum-=a[l++];
}
}
if(ans==INF) printf("-1");
else printf("%lld",ans);
}
int main(){
solve();
return 0;
}边栏推荐
- SRM系统可以为企业带来什么价值?
- SSH protocol learning notes
- 基于STM32F103ZET6库函数独立看门狗(IWDG)实验
- mongoTemplate - distinct 使用
- 给定一个数在序列中求最大异或值(01字典)
- How to create and delete MySQL triggers
- 3h精通OpenCV(七)-颜色检测
- Have you grasped the most frequently asked question in the interview about massive data processing?
- Industry application of smart city based on GIS 3D visualization
- Professor of Cambridge University: eating breakfast often is harmful and dangerous. - you know what
猜你喜欢

软件测试——基础理论知识你都不一定看得懂

VB. Net read / write NFC ntag tag source code

Image migration and data migration synchronization of old and new servers with different Alibaba cloud accounts

DevCloud加持下的青软,让教育“智”上云端

面试中问最常问的海量数据处理你拿捏了没?

On adding and subtracting dates

Yurun multidimensional makes efforts in the charity field and bravely resists the corporate public welfare banner

Selenium upload file

小程序容器是什么技术?能助力物联网企业红海突围?

ISO 32000-2 国际标准7.7
随机推荐
How MySQL queries character set codes of tables
小程序容器是什么技术?能助力物联网企业红海突围?
Serial port experiment based on stm32f103zet6 library function
[Oracle] basic knowledge interview questions
基于gis三维可视化的智慧城市行业运用
lodash深拷贝使用
DevCloud加持下的青软,让教育“智”上云端
Cross border independent station language Unicode to Hebrew
Digital twin energy system, creating a "perspective" in the low-carbon era
迈动互联中标大家保险集团
Openfeign use step polling strategy and weight log4j configuration of openfeign interceptor
面试中问最常问的海量数据处理你拿捏了没?
Web Scraping with Beautiful Soup for Data Scientist
设置双击运行 jar 文件
Visual studio plug-in coderush officially released v22.1 -- visual tool for optimizing debugging
mongoTemplate - distinct 使用
Opencv+yolo-v3 for target tracking
QQ如何开通在线客服
Bottom level internal skill cultivation
ISO 32000-2 国际标准7.7