平常水题 - atcoder 062 - D - 3N Numbers

Windows下QT5.15.2安装MQTT模块全攻略(附分支选择避坑指南) 本文详细介绍了在Windows环境下为QT5.15.2安装MQTT模块的完整流程,包括环境准备、源码获取、编译配置及项目集成等关键步骤。特别针对分支选择、依赖项处理和常见错误提供了实用解决方案,帮助开发者高效完成MQTT模块的安装与调试,适用于物联网开发场景。 阅读详情
D - 3N Numbers
Time limit : 2sec / Memory limit : 256MB

Score : 500 points

Problem Statement
Let N be a positive integer.

There is a numerical sequence of length 3N, a=(a1,a2,…,a3N). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a')−(the sum of the elements in the second half of a').

Find the maximum possible score of a'.

Constraints
1≤N≤105
ai is an integer.
1≤ai≤109
Partial Score
In the test set worth 300 points, N≤1000.
Input
Input is given from Standard Input in the following format:

N
a1 a2 … a3N
Output
Print the maximum possible score of a'.

Sample Input 1
Copy
2
3 1 4 1 5 9
Sample Output 1
Copy
1
When a2 and a6 are removed, a' will be (3,4,1,5), which has a score of (3+4)−(1+5)=1.

Sample Input 2
Copy
1
1 2 3
Sample Output 2
Copy
-1
For example, when a1 are removed, a' will be (2,3), which has a score of 2−3=−1.

Sample Input 3
Copy
3
8 2 2 7 4 6 5 3 8
Sample Output 3
Copy
5

For example, when a2, a3 and a9 are removed, a' will be (8,7,4,6,5,3), which has a score of (8+7+4)−(6+5+3)=5.


题意:给一个长度位 3 * n 的序列a,删除 n 个数,形成一个长度位2 * n的新序列a'(顺序未改变).并使新的序列前n个数的和 - 后n个数的和最大。


解题思路:用优先队列(能弹出最小的数)维护新序列a‘前n个数的最大和,用优先队列(能弹出最大的数)维护新序列a'的最小和。

求新序列的前 n 个数的最大和:先从前开始枚举原序列a,若队列里的元素大于n就弹出队列里最小的数,用dp_f[i] 来记入在前i(包括i)个数挑选n个数的最大和。

求新序列的后 n 个数的最小和:从后开始枚举原序列的a,若队列里的元素大于n就弹出队列里最大的数,dp_e[i] 来记入在i(包括i)之后挑选n个数的最小和。


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;

const long long MAX = -1e18;
const long long MAXN = 3e5 + 5;
long long dp_f[MAXN],dp_e[MAXN],a[MAXN];

priority_queue<long long , vector<long long> , greater<long long> > que;
priority_queue<long long>pque;

void Slove_f(int n){
	long long sum_f = 0;
	for(int i = 1;i <= 3 * n;i++){
		que.push(a[i]);
		sum_f += a[i];
		dp_f[i] = sum_f;
		if(que.size() > n){
			sum_f -= que.top();
			que.pop();
			dp_f[i] = sum_f;
		}
	}

}

void Slove_e(int n){
	long long sum_e = 0;
	for(int i = 3 * n;i >= 1;i--){
		pque.push(a[i]);
		sum_e += a[i];
		dp_e[i] = sum_e;
		if(pque.size() > n){
			sum_e -= pque.top();
			pque.pop();
			dp_e[i] = sum_e;
		}
	}

}

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= 3 * n;i++) scanf("%lld",&a[i]);

	Slove_f(n);	
	Slove_e(n);

	long long ans = MAX;
	for(int i = n;i <= 2 * n;i++){
		ans = max(ans,dp_f[i] - dp_e[i + 1]);
	}
	printf("%lld",ans);
}


NEU-DET 冷轧钢缺陷检测:基于 YOLOv8 的目标检测与可视化 UI 实现 冷轧钢的生产过程中,由于设备故障、工艺问题或者人为因素,钢板表面可能会出现多种缺陷,如划痕、裂纹、孔洞等,这些缺陷会严重影响钢材的质量。它比之前的版本(如 YOLOv5、YOLOv4)在速度和精度上都有显著提升,并且对硬件要求较低,适合进行工业界面和嵌入式系统的应用。这些版本相较于更大型的模型(如 YOLOv8x)具有更快的推理速度和较低的资源占用,适合工业生产线中的实时应用。通过将训练好的模型部署到工业生产线摄像头中,我们可以实现实时的缺陷检测,极大地提升生产效率和产品质量。 阅读详情

相关推荐

Windows Server+SqlServer Always On实战:5步搞定高可用集群搭建

本文详细介绍了在Windows Server环境中,通过5个关键步骤搭建SQL Server Always On高可用集群的实战指南。内容涵盖从底层故障转移集群配置、SQL Server实例启用Always On功能,到创建可用性组和侦听器的完整流程,并提供了核心运维与故障排查思路,帮助企业构建稳定可靠的数据库高可用架构。

milk5的博客 872

【ATcode】3N Numbers(优先队列 枚举n+1~2*n区间)

题目大意 题目大意:给出你一个N,会给你3*N个数,然后让你删去N个数,保证其中的前N个数,和后N个数的差值是最大的。 思路:首先对于这个题目,我们知道这个题目的最终界限一定在n~2*n这个范围内,那么我们不妨用两个优先队列把前面的N个数给存储起来,也把后面的N个数都储存起来,如果我们在n+1~2*n中遇到了比保存前面的值更大的值,那么我们就可以进行替换,后面的也是一样的, 不过要注意...

红点雷龙XL 421

如何把DeepSeek这个奈斯工具接入到Pycharm里

DeepSeek接入到Pycharm中,提高编程效率,以及帮助解决遇到的问题。

学无止境,何以言满 2631

AtCoder-abc062_a

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); int m = sc.nextInt(); int[] arr1 =.

qq_53324833的博客 188

小白投资理财 - 解读威廉分形指标 Williams Fractals

威廉分形指标用于识别价格趋势中的关键点,帮助判断支撑位和阻力位。

wumingxiaoyao的博客 4357

量化回测框架三选一:Backtrader、Zipline、PyAlgoTrade,新手到底该跟谁学?

本文对比分析了三大量化回测框架Backtrader、Zipline和PyAlgoTrade,帮助新手选择最适合的入门工具。从安装配置、策略编写到文档查阅,详细解析各框架的特点和适用场景,为量化交易初学者提供实用指南。

weixin_28745309的博客 279

3N Numbers(AtCoder-2566)

Problem Description Let N be a positive integer. There is a numerical sequence of length 3N, a=(a1,a2,…,a3N). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements f...

Alex_McAvoy的博客 482

加速访问Cloudflare的网站的解决方案

本文主要介绍了加速访问Cloudflare的网站的解决方案,希望能对大家有所帮助。通过软件计算得到最快的IP地址的效果图如下图所示,具体解决方案参考下文。 在这里插入图片描述 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 1万+

atcoder 062D - 3N Numbers

http://abc062.contest.atcoder.jp/tasks/arc074_b 题意就是说 给你3n个数,之后删除n个数,使得前n个数 减去 后面 n个数之后的差值最大思路: 用2个优先队列搞一下就行。一个维护最大值,一个维护最小值,并且我们知道最后这2n个数的分界点一定是在n~2n这N个数之间的。 那么我们可以对N个数求和,对后n个数求和,之后我们在n~2n中找到分界点即可。#i

My_stage的博客 882

【产品经理修炼之道】- 优惠券系统从入门到精通(二)

在电商平台中,优惠券的使用场景与频次都很高。那么如何做好一个优惠券系统呢?本文总结了相关流程和设计思路,希望对你有所帮助。上一篇与大家分享了架构中的前端应用、生命周期、优惠券管理中OpenAPI 、基础系统,今天继续与大家分享架构图中优惠券模板部分。

xiaoli8748的专栏 1299

2024-江苏科技大学-模拟-动态接触角,模拟液滴撞击,comsol软件模拟。

相反,其对液滴粘度和平衡接触角的变化基本不敏感。重力势能的影响显著受过程参数调节,随着液滴直径和密度的增加而增加,而随着初始液滴速度和表面张力系数的增加而减小。通过考虑形状因子和粘度修正因子,可以准确定义表面能和粘性耗散能,使得所提出的半经验修正勺状模型表现出良好的性能,在所有65个研究案例中,液滴最大铺展长度因子(βmax)和中心厚度(h)的相对误差基本分别落在5%和10%的区间内。重力势能的影响受过程参数显著调节,随液滴直径和密度的增大而增大,随液滴初始速度和表面张力系数的增大而减小。

qq_15963745的博客 516

[Codeforces] number theory (R1900) Part.1

[Codeforces] number theory (R1900) Part.1

Hytidel的博客 820

AI测试实战:手把手教你做LLM(大模型)性能测试「含完整代码」

大模型API性能测试是评估模型服务响应能力、吞吐量和资源效率的关键手段。核心指标包括总响应时间、吐字率、首token延迟、输入/输出tokens数量、QPM等。测试流程涵盖构造负载、并发请求、数据采集和指标计算。优化建议针对吐字率低、首token延迟高、QPM偏低等问题,从模型、硬件、系统等多层面提出解决方案。

blues_C的博客 1439

Atcoder D - 3N Numbers(优先队列+dp)

题目链接:http://abc062.contest.atcoder.jp/tasks/arc074_b 题意:给出3*n个数要求去掉n个数使得剩下的前n个数-后n个数的差最大。 题解:显然是一道如果数据小直接dpf[i][j]表示前i个取j个最大是多少,dpe[i][j]后i个取j个最小是多少。 显然转移也是很明显的dpf[i][j]=max(dpf[i][j],dpf[i...

awow80285的博客 308

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

AtCoder:3N Numbers(优先队列)

D - 3N Numbers Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Let N be a positive integer. There is a numerical sequence of length 3N, a=(a1,a2,…,a3N).

junior19的博客 592

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

AtCoder - 2566 优先队列

AtCoder - 2566 优先队列 Let N be a positive integer. There is a numerical sequence of length 3N, a=(a1,a2,…,a3N). Snuke is constructing a new sequence of length 2N, a', by removi...

loooooog的博客 335

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

LeetCode(1-50)

LeetCode 编程 1. Two Sum   Given an array of integers, return indices of the two numbers such that they add up to a specific target.   You may assume that each input would have exactly one soluti...

LintaoD的博客 1254

3N Numbers

D - 3N Numbers Time limit: 2sec /Memory limit: 256MB Score :500points Problem Statement LetNbe a positive integer. There is a numerical sequence of length3N,a=(a1,a2,…,a3N). Snuke is...

weixin_33736048的博客 217

平常水题 - Sheldon Numbers(逆向思维,位运算)

Sheldon Numbers According to Sheldon Cooper, the best number is 73. In his own words, “The best number is 73. 73 is the 21st prime number. Its mirror, 37, is the 12th, and its mirror, 21, is the pr

dreams___的博客 1182

AT - Grand - 004 - B - Colorful Slimes(思维理解)

B - Colorful Slimes Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come...

dreams___的博客 936

平常水题 - 蚂蚁(栈的使用)

蚂蚁 Time limit per test: 0.5 seconds Time limit all tests: 5.0 seconds Memory limit: 256 megabytes 水平线上有 N 只蚂蚁,每只蚂蚁的位置及大小均不同。他们沿着 X 轴爬行,有的向左,有的向右,爬行的速度是一样的,两只蚂蚁相遇大一点的会吃掉小的。 现在从左到右给出每只蚂蚁的大小和爬行的

dreams___的博客 891

平常水题 - J. Architect of Your Own Fortune (二分图匹配)

J. Architect of Your Own Fortune Vasya is a schoolboy who rides a trolley bus and then a bus to get to school. He’s always very happy to get a “lucky ticket,” which means the total of the first thre

dreams___的博客 880

寒武纪重现(HDU)- 1008(6261) - Rikka with Mutex(二分 + 错误总结)

Rikka with Mutex Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 32 Accepted Submission(s): 12 Problem Description Sometimes, technica...

dreams___的博客 857

平常水题 - Atcoder 058 - C - 怪文書 / Dubious Document(字符串的处理)

C - 怪文書 / Dubious Document                                                       Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Snuke loves "paper cutting": he c

dreams___的博客 808

CF - div2 - 459 - C - The Monster

C. The Monster time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output As Will is stuck in the Upside Down, he can still communicate with his mom,

dreams___的博客 795

D. Almost Identity Permutations(dp)

D. Almost Identity Permutations time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A permutation p of size n is an array such that every inte

dreams___的博客 773
上一篇: 平常水题 - 蚂蚁(栈的使用)
下一篇: map 数组里放 pair 或 结构体
dwenhu___
博客等级 码龄10年 8粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值