Maximum Absurdity(dp)

【202503】Wan:开放且先进的大规模视频生成模型【1.3B、14B】【支持对无限长度视频进行稳定的Inference】【Wan中的主要计算开销来自注意力机制】 wan: Open and Advanced Large-Scale Video Generative ModelsWan:开放且先进的大规模视频生成模型Wan Team, Alibaba Group Wan 团队,Alibaba GroupThis report presents Wan, a comprehensive and open suite of video foundation models designed to push the boundaries of video generation 阅读详情

Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.

This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 ≤ a ≤ b ≤ n - k + 1, b - a ≥ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).

As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.

Input
The first line contains two integers n and k (2 ≤ n ≤ 2·105, 0 < 2k ≤ n) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, …, xn — the absurdity of each law (1 ≤ xi ≤ 109).

Output
Print two integers a, b — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.

Sample test(s)
input
5 2
3 6 1 1 6
output
1 4
input
6 2
1 1 1 1 1 1
output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.

In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.

给一个长度为n的序列,找两个不相交的长度为k的子串,使他们的和最大,输出两个子串的起始位置。

处理不好就超时了= = ,之前超时的忘了,第二次写一下就想到正解了。
首先预处理出已这个位置为起始位置长度为k的和,
对于每个i,i表示后面那个长度为k的子串,那么对于它来说,最大的子串和就是前i个位置中最大的那一个,就是第一个子串的位置。
问题转化成快速找前i个中最大的子串,然后发现这个在遍历i的时候就可以快速处理,
i每次改变1,那么前i个中最大的子串其实只需要用前i - 1个中最大子串和新出现的子串比较即可。
具体理解可以画一画图示意一下。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
ll a[200005],dp[200005];
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    ll n,k;
    scanf("%lld%lld",&n,&k);
    for(ll i = 1;i <= n;i++)
        scanf("%lld",&a[i]);
    ll ans = 0;
    for(ll i = 1;i <= k;i++)
        ans = ans + a[i];
    dp[1] = ans;
    for(ll i = 2;i <= n - k + 1;i++)
    {
        ans = ans + a[i + k - 1] - a[i - 1];
        dp[i] = ans;
    }
    ans = dp[1] + dp[k + 1];
    ll pos = 1,pos1,pos2;
    pos1 = 1;pos2 = k + 1;
    for(ll i = k + 2;i <= n - k + 1;i++)
    {
        if(dp[i - k] > dp[pos])pos = i - k;
        if(dp[i] + dp[pos] > ans)
        {
            ans = dp[i] + dp[pos];
            pos1 = pos;
            pos2 = i;
        }
    }
    printf("%lld %lld\n",pos1,pos2);
    return 0;
}
PromptBio实战:如何用AI对话搞定转录组数据分析(附详细操作截图) 本文详细介绍了如何利用PromptBio平台通过AI对话完成转录组数据分析,无需编程基础即可实现从数据上传到结果解读的全流程。文章包含详细的操作截图和参数配置建议,帮助科研人员快速掌握这一生信分析工具,显著提升研究效率。 阅读详情

相关推荐

Edge浏览器IE模式失效?最新142版本隐藏按钮的3种解决方案

本文针对Edge浏览器142版本中IE模式按钮消失的问题,提供了3种实用解决方案,包括注册表修改、手动添加网站到IE模式列表和企业策略部署方案,帮助用户解决兼容性问题,确保老旧系统正常访问。

weixin_28308325的博客 503

Maximum Absurdity(dp思想+前缀和)

Maximum Absurdity 原题目:Maximum Absurdity 题解 处理长度为 k 的区间和用前缀和 处理不相交的两个区间和用 dp 思想,以 i 为界线,用四个数组分别记录位置 i 之前的区间和最优解以及位置和 i 之后的区间和最优解以及位置,然后遍历 i 得出最优解,巧妙解决不相交问题。 code #include<iostream> using namespace std; int n, k; int num[200010], index1[200010], in

Mei_Tou_Nao_的博客 219

IC面试常考题 Verilog三分频电路设计(占空比50%,三分之一,三分之二)

实现三分频电路最简单的是: 利用计数器实现。 时序图分析(本人比较懒,平常科研忙,所以直接手画时序图了,懒得用软件画了): 直接上图分析:利用计数器每隔三个周期信号翻转一次,同时在不同的计数下翻转得到的同步信号 clk_1和clk_2,再利用异或即可实现出一个不同占空比的三分频信号(同样的方法也可扩展到其他奇数分频设计中)。 例如占空比50%: module Div_three( input clk, input rst_n, output div_three ); reg

qq_41884662的博客 1万+

Maximum Absurdity

题目描述 Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all the...

qq_17853613的博客 307

基于LabVIEW控制仪器检测与监控 --普源示波器DS1102Z-E

LabVIEW 控制普源示波器 代码实现与解释

s0101100的博客 4233

医院网络设计(完整文档+思科拓扑图)

大家好,我是小华学长,一名计算机领域的博主。经过多年的学习和实践,我积累了丰富的计算机知识和经验,在这里我想与大家分享我的学习心得和技巧,帮助你成为更好的程序员。作为一名计算机博主,我一直专注于编程、算法、软件开发等领域,在这些方面积累了大量的经验。我相信分享是一种双赢的方式,通过分享,我可以帮助他人提升技术水平,同时也能够得到学习交流的机会。在我的文章中,你将会看到我对于各种编程语言、开发工具以及常见问题的解析和分析。我会结合自己的实际项目经验,为你提供实用的解决方案和优化技巧。

qq1325513482的博客 2万+

CodeForces - 332B. Maximum Absurdity(前缀和+dp)

B. Maximum Absurditytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputReforms continue entering Berland. For example, during yesterday sitting the B...

I_believe_CWJ的博客 523

Lane、PHY和Preset Value Bit

每个Lane支持不同的传输速度和带宽,例如PCIe 3.0中,一个Lane的传输速度可以达到8 GT/s(Giga Transfers per second),也就是1 GB/s(GigaBytes per second)。Preset Value Bit(预置值位)是在PCIe 3.0的Lane上新引入的一种机制,用于优化信号传输质量。PCIe设备可以包含多个Lane,例如x1、x4、x8、x16等,表示该设备同时使用的Lane数目,比如x16表示该设备采用了16个Lane,具有更高的传输速度和带宽。

weixin_58083606的博客 1296

B. Maximum Absurdity

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Reforms continue entering Berland. For example, during yesterday

无知的我 1776

OpenCV计算机视觉实战(12)——图像金字塔与特征缩放

图像金字塔技术通过对原始图像按不同分辨率进行多层次表示,不仅能提升计算效率,还能为图像融合、检测与识别提供多尺度特征。高斯金字塔 (Gaussian Pyramid) 用于构建多级低通图像,拉普拉斯金字塔 (Laplacian Pyramid) 则提取各层之间的细节信息。本节将深入介绍如何使用 OpenCV 构建高斯与拉普拉斯金字塔,并以经典的图像融合案例,展示图像金字塔在特征缩放与融合中的强大应用。

qq_30167691的博客 1404

MISRA C 详解 · 专栏06:2023 与 2025 更新总览(相对 2012 的差异)

本专栏 01~05 篇基于(143 规则 + 16 指令)。这六年间标准又前进了两步——(大改)和(微调)。本文补充说明「相对 2012,标准变在哪」,并给出新增规范的代表性示例。

XavierKong的博客 73

codeforces B.Maximum Absurdity 解题报告

题目链接:http://codeforces.com/contest/332/problem/B 题意:在一个序列中,在所有长度为k的区间里找出两个不重叠的最大和,输出这两个最大和所对应的开头的位置a和b。 一开始没有想到用dp来做,于是有了以下的错误思路(读者可以忽略):声明一个结构体,包括head(保存起始点)、tail(保存结束点)还有sum(保存长度为k的区间的和)。计算出整...

weixin_30528371的博客 174

WinClaw安全实战 02|五层纵深防护体系全解析:从原理到实操,打造零风险AI智能体

2026年AI智能体爆发式普及,OpenClaw以27.3万GitHub星标成为现象级工具,但恶意Skill投毒、提示词注入、数据外泄等安全事故频发,国家互联网应急中心、工信部等多部门接连发布风险警示。威努特基于国家关键信息基础设施安全防护经验,打造WinClaw安全版AI智能体,其核心竞争力在于**五层纵深防护体系**。本文从安全痛点切入,通过真实事故案例揭示风险本质,全景解构五层防护的架构设计与技术原理,逐层拆解身份认证、安装审查、消息拦截、执行约束、监控审计的实现逻辑,搭配20+实操演示、对比表格

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 497

Maximum Absurdity DP + 数学

Maximum Absurdity Time Limit:2000MSMemory Limit:262144KB64bit IO Format:%I64d & %I64u SubmitStatus Appoint description: System Crawler (2013-07-28) Description ...

weixin_30550271的博客 114

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

[CodeForces 332B]Maximum Absurdity[DP]

题目链接:[CodeForces 332B]Maximum Absurdity[DP] 题意分析: 寻找两个不重叠的长度为k的子串,使得它们之和最大。 解题思路: 第一想法是,处理出从这个点开始,长度为k的区间的总和,即getv[i]代表区间[i, i + k - 1]的和,然后想着这个能怎么用? 然后发现可以处理出来之后,从getv[1]开始枚举,dp[i]代表从i开始,和最大的区间和

闲停 503

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

codeforces 332b Maximum Absurdity dp

题意: 有n个数,找两个段(每个段长度为k)不相交,求出这两个段的和的最大值。 输出两个段的起始下标。 思路: dp[i][j]:走到i,已经选了j个段的最大值。 转移:dp[i][j] = dp[i-k][j-1] + sum[i]-sum[i-k]; 输出方案的话,根据dp的值dfs回去(不dfs也是可以的),因为方案已经记录在dp的转移中。 code: #include #

553

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

CF 332 B.Maximum Absurdity【DP】

Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws

Irish_Moonshine的博客 617

codeforces332B - Maximum Absurdity 线段数 or dp

题意:给你一个序列,找两个长度为 k 且没有重合区间的数使得其和最大 解题思路: 1)线段树 想了半天想不出只能先用线段树撸了一发,这题dp 第一名只要了 9分钟。 就是把起点为 i 长度为 k 的和预处理出来,再用线段树枚举去找。 解题代码: 1 // File Name: 332b.cpp 2 // Author: darkdream 3 // Creat...

weixin_30535843的博客 138

Codeforces Round #193 (Div. 2) B. Maximum Absurdity (DP、RMQ两种解法)

B. Maximum Absurdity time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Reforms continue entering Berland. For

To be what you what to be! 1366

Codeforces 332B Maximum Absurdity(DP+前缀和处理)

题目链接:http://codeforces.com/problemset/problem/332/B 题目大意:给你n个数和一个整数k,要求找到不相交的两个长度为k的区间,使得区间和最大,输出这两个区间的起点。解题思路:先计算前缀和,然后预处理出maxsum[i],maxsum[i]记录i~n最大的长度为k子段的和。然后再去枚举即可。 1 #include<cstdio...

weixin_30648587的博客 132

CodeForces 332B Maximum Absurdity

题目大意: 给出一个序列,让找出不互相覆盖的两个长度为k的段,问在两个段的权值和最大的情况下,按照左边段的左端点排序,右边段的左端点作为第二关键字排序,得到的第一个答案。 题目分析: dp:dp1[maxn],dp2[maxn]; dp1【i】表示前i项连续k段最大值,dp2【i】表示后n-i项连续k段最大值,然后做一次循环就好 #include #i

Ezereal的博客 590

codeforce 332B Maximum Absurdity

原题链接 题意 一个长为N的序列,选择其中2个长为K的不相交区间,使两个区间和最大 题解 CF标签上写的好好的DP,做着做着发现就是前缀和思想嘛,哪里有DP?哪里有DP? #include using namespace std; typedef long long LL; const int maxn=2e5; LL sum[maxn+5]; LL prem

zwsign的博客 455

codeforces 332B B. Maximum Absurdity(rmq)

题目链接:codeforces 332B题目大意:给出一个序列,让找出不互相覆盖的两个长度为k的段,问在两个段的权值和最大的情况下,按照左边段的左端点排序,右边段的左端点作为第二关键字排序,得到的第一个答案。题目分析: 很水的数据结构的题目,我们只需要先利用前缀和预处理出所有长度为k的段的总权值。然后利用rmq维护区间最大值和得到这个最大值取得的段的最左位置。 然后我们枚举第二段的位置,然后找到在采

llin-黎辰 2682

Codeforces 332B Maximum Absurdity(暴力)

题意:给你一个序列,让你在里面选择两个不想交的长度为k的字段,是的和最大。 我第一次做还是用的dp,感觉复杂度有点高啊,后来发现直接预处理就好了。 预处理需要三个数组,分别是sum[i],Max[i],Max_id[i]。 sum[i]表示以i开头的长度为k的子段和 Max[i]表示在i之后的和最大的长度为k的字段和 Max_id[i]和上面对应,就是那个最大子段和的其实位置。 这样处理好之后=,直

只玩三国的程序猿的专栏 688

CodeForces 332 B. Maximum Absurdity 动规 求和最大的两段连续子列

前面做过好几个最大连续子列的问题,这个题是找两个已知长度的子列,满足这两段的和最大这一条件。核心是动规以及树状数组。 先说一下树状数组:第一个是sum[i]=sum[i-1]+num[i];以及seq[i]=sum[i+k-1]-sum[i-1];seq[i]表示i到i+k-1的和。 动规:dp[i]=a表示在以第i到n-k+1为起点的长度为k的子列中以a为起点的最大。状态转移方程是  若se

anqier0468的专栏 881

codeforces B. Maximum Absurdity 线段树查找最大值的位置

B. Maximum Absurdity time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Reforms continue entering Berland. For

liyunlonghere 695
上一篇: Writing Code(DP)
下一篇: A and B and Interesting Substrings(dp)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值