内存限制:256 MiB 时间限制:1000 ms 标准输入输出
                          题目类型:传统 评测方式:文本比较

题目描述

给定一个长度为 nnn 的序列 AAA 。

定义 f(l,r)=∑i=lrAif(l,r)=\sum_{i=l}^{r} A_{i}f(l,r)=∑​i=l​r​​A​i​​。

询问 mmm 次,每次询问一个数字 xxx,请求出所有满足 r−l+1≥xr-l+1 \ge xr−l+1≥x 区间 [l,r][l,r][l,r] 中最大的 f(l,r)f(l,r)f(l,r)。

输入格式

第一行两个数,表示 nnn 和 mmm 。
之后 nnn 个数,表示序列 AAA。
之后 mmm 行每行一个数 xxx,表示询问 xxx 。

输出格式

输出 mmm 行,每行一个答案,表示最大的 f(l,r)f(l,r)f(l,r) 。

样例

样例输入

5 5
1 2 3 4 5
1
2
3
4
5

样例输出

15
15
15
15
15

数据范围与提示

前缀和就好

屠龙宝刀点击就送

#include <cstring>
#include <cstdio>
#define N 10005 int sum[N],maxn[N],n,m;
inline int max(int a,int b) {return a>b?a:b;}
int main()
{
memset(maxn,-0x3f,sizeof(maxn));
scanf("%d%d",&n,&m);
for(int a,i=;i<=n;++i)
scanf("%d",&a),sum[i]=sum[i-]+a;
for(int i=;i<=n;++i)
for(int j=;j<=i;++j)
maxn[i-j+]=max(maxn[i-j+],sum[i]-sum[j-]);
for(int i=;i<=n;++i)
for(int j=i+;j<=n;++j)
maxn[i]=max(maxn[i],maxn[j]);
for(int x;m--;)
{
scanf("%d",&x);
printf("%d\n",maxn[x]);
}
return ;
}

LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意的更多相关文章

  1. Loj514「LibreOJ β Round #2」模拟只会猜题意 - 模拟

    注意初始化即可. #include <bits/stdc++.h> using namespace std; ],a[],t1,t2,t3,t4; int main(){ memset(a ...

  2. 汕头市队赛 SRM10 T1模拟只会猜题意

    模拟只会猜题意 SRM 10 描述 有一本n个单词的词典,求按下列方法能造出的不相同的词汇数目.  1.词典中的单词是一个词. 2.能分为两部分的,其中前一部分是一个词典词或者其非空前缀,后一部分是一 ...

  3. loj514模拟只会猜题意

    果然是道模拟... 一开始想线段树 看了一眼数据范围:“这tm不是前缀和吗” 然后水过 #include<iostream> #include<cstdio> #include ...

  4. LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力

    二次联通门 : LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 /* LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 叫做计算几 ...

  5. LibreOJ #528. 「LibreOJ β Round #4」求和

    二次联通门 : LibreOJ #528. 「LibreOJ β Round #4」求和 /* LibreOJ #528. 「LibreOJ β Round #4」求和 题目要求的是有多少对数满足他们 ...

  6. LibreOJ #527. 「LibreOJ β Round #4」框架

    二次联通门 : LibreOJ #527. 「LibreOJ β Round #4」框架 /* LibreOJ #527. 「LibreOJ β Round #4」框架 %% xxy dalao 对于 ...

  7. LibreOJ #526. 「LibreOJ β Round #4」子集

    二次联通门 : LibreOJ #526. 「LibreOJ β Round #4」子集 /* LibreOJ #526. 「LibreOJ β Round #4」子集 考虑一下,若两个数奇偶性相同 ...

  8. LibreOJ #525. 「LibreOJ β Round #4」多项式

    二次联通门 : LibreOJ #525. 「LibreOJ β Round #4」多项式 官方题解 : /* LibreOJ #525. 「LibreOJ β Round #4」多项式 由于会有多种 ...

  9. LibreOJ #524. 「LibreOJ β Round #4」游戏

    二次联通门 : LibreOJ #524. 「LibreOJ β Round #4」游戏 /* LibreOJ #524. 「LibreOJ β Round #4」游戏 找找规律就会发现.. 当有X的 ...

随机推荐

  1. STL::next_permutation();

    next_permutation()可以按字典序生成所给区间的全排列. 在STL中,除了next_permutation()外,还有一个函数prev_permutation(),两者都是用来计算排列组 ...

  2. 转:AppScan代理扫描app/H5安全测试

    1.首先设置AppScan代理,设置如下:

  3. (二)搭建SSH环境

    一.struts 1.添加jar包: commons-fileupload-1.3.1.jar,[文件上传相关包] commons-io-2.2.jar, commons-lang-2.4.jar , ...

  4. 线性Softmax分类器实战

    1 概述 基础的理论知识参考线性SVM与Softmax分类器. 代码实现环境:python3 2 数据预处理 2.1 加载数据 将原始数据集放入"data/cifar10/"文件夹 ...

  5. 盛大游戏技术总监徐峥:Unity引擎使用的三种方式

    在5月13日Unite 2017 案例分享专场上,盛大游戏技术总监徐峥分享了使用Unity引擎的三种方式,以下为详细内容: 大家好,我先简单介绍一下我自己,我是盛大游戏的技术总监徐峥.我今天想分享的主 ...

  6. Unity3D 自动添加Fbx Animation Event

    http://blog.csdn.net/aa20274270/article/details/52528449 using UnityEngine; using System.Collections ...

  7. JDK12下的ArrayList源码解读 与 Vector的对比

    ArrayList源码阅读. //测试代码实现如下 private static void arrayList() { ArrayList<String> list = new Array ...

  8. glassfish cluster 搭建

    http://blog.csdn.net/wych1981/article/details/8815150

  9. SpringBoot用户CRUD

    1.准备 http://start.spring.io/ 这里地址去直接生成你需要的项目信息,如何你本身ide以及集成了springboot 那么可以直接生成项目信息 需要的知识:java,sprin ...

  10. 洛谷P4238【模板】多项式求逆

    洛谷P4238 多项式求逆:http://blog.miskcoo.com/2015/05/polynomial-inverse 注意:直接在点值表达下做$B(x) \equiv 2B'(x) - A ...