码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • AtCoder_abc267_c


    链接

    • 点此跳转

    思路

    预处理前缀和,处理一下偏移量。

    代码

    // #pragma GCC optimize(3)
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #define endl '\n'
    #define fi first
    #define se second
    #define PI acos(-1)
    #define LL long long
    #define INF 0x3f3f3f3f
    #define lowbit(x) (-x&x)
    #define PII pair<int, int>
    #define ULL unsigned long long
    #define PIL pair<int, long long>
    #define mem(a, b) memset(a, b, sizeof a)
    #define rev(x) reverse(x.begin(), x.end())
    #define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    
    using namespace std;
    
    const int N = 2e5 + 10;
    
    int n, m;
    LL a[N], sum1[N], sum2[N];
    
    void solve() {
    	cin >> n >> m;
    	LL ans = -1e18;
    	for (int i = 1; i <= n; i ++ ) {
    		cin >> a[i];
    		sum2[i] = sum2[i - 1] + a[i];
    		sum1[i] = sum1[i - 1] + i * a[i];
    		if (i > m) {
    			ans = max(ans, 
    			sum1[i] - sum1[i - m - 1] - (sum2[i] - sum2[i - m - 1]) * (i - m)); 
    		} else if (i == m) ans = max(ans, sum1[m]);
    	}
    	cout << ans << endl;
    }
    
    int main() {
    	IOS;
    	
    	solve();
    	
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
  • 相关阅读:
    linux下命令操作
    【分布式锁篇】Redisson详解
    【第30天】给定一个整数 n ,求它的因数之和
    jdk 中的 keytool 的使用,以及提取 jks 文件中的公钥和私钥
    2024能源动力、机械自动化与航天航空技术国际学术会议(ICEPMAT2024)
    通过阿里云server配置属于自己的云笔记leanote
    测试开发(6)软件测试教程——自动化测试selenium(自动化测试介绍、如何实施、Selenium介绍 、Selenium相关的API)
    EXCEL地图 | 制作民生银行网点地图
    计算机网络 数据链路层课后题
    Windows下编译安装FreeCAD 0.21
  • 原文地址:https://blog.csdn.net/weixin_60484917/article/details/127857575
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号